Software Development Network>> Visual Basic>> Subnet Mask
I am looking for that too. You can however get that info from win32 wmi class lib.
Win32_NetworkAdapterConfiguration and the IPSubnet is the property of that class.
But how the heck do u do it in .net Everyone has given the example of how to get the IP Address using this code
Dim IpEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(Environment.MachineName)
Dim IpAddr As System.Net.IPAddress() = IpEntry.AddressList
Console.WriteLine(IpAddr(IpAddrIndex).ToString)
Next
the above code is from pcelement see this thread
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=223586&SiteID=1
I was thinking that the guys who wrote that class tho forgot about all the other parts of the IpAddress. Subnet dns, gateway etc....
Of course we want to do everything with .net now, no more funky win32 stuff right
I am just trying to learn like the rest!!
.net 2.0 doesnt have the facility of subnet mask
the only way left is to use WMI
i have already done it
Here it is. Dont forget to add reference to system.mangement assembly.
Sub GetSubnetMask()
Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMOC As ManagementObjectCollection = objMC.GetInstances()
Dim objMO As ManagementObject
Dim subnets As String()
For Each objMO In objMOC
If subnets IsNot Nothing Then
Console.WriteLine(String.Format("Subnet Mask: {0}", subnets(0)))
End If
End Sub
Subnet Mask
Oscar Calvo
I am looking for that too. You can however get that info from win32 wmi class lib.
Win32_NetworkAdapterConfiguration and the IPSubnet is the property of that class.
But how the heck do u do it in .net Everyone has given the example of how to get the IP Address using this code
Dim IpEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(Environment.MachineName)
Dim IpAddr As System.Net.IPAddress() = IpEntry.AddressList
Dim IpAddrIndex As IntegerFor IpAddrIndex = 0 To IpAddr.Length - 1
Next
the above code is from pcelement see this thread
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=223586&SiteID=1
I was thinking that the guys who wrote that class tho forgot about all the other parts of the IpAddress. Subnet dns, gateway etc....
Of course we want to do everything with .net now, no more funky win32 stuff right
I am just trying to learn like the rest!!
DrBytes
.net 2.0 doesnt have the facility of subnet mask
the only way left is to use WMI
i have already done it
Here it is. Dont forget to add reference to system.mangement assembly.
Sub GetSubnetMask()
Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMOC As ManagementObjectCollection = objMC.GetInstances()
Dim objMO As ManagementObject
Dim subnets As String()
For Each objMO In objMOC
subnets = CType(objMO("IPSubnet"), String())If subnets IsNot Nothing Then
Console.WriteLine(String.Format("Subnet Mask: {0}", subnets(0)))
End If
Next
End Sub
Chennai BOY