CryoEnix Posted December 11, 2004 Posted December 11, 2004 Hi there, I've been playing around with networking in .NET lately, and I've managed to develop a function to return all of the IP addresses of the local machine - yay! But I digress... The problem is, I need to find the subnet mask for each of these IP addresses - for example, if I were to pass the IP "192.168.0.1" to a function, I would like it to return the subnet (in this case "255.255.255.0"), or even just a string/boolean telling me if it's a LAN or Internet IP. Anyone? Quote Chaos is merely logic beyond human comprehension
Administrators PlausiblyDamp Posted December 11, 2004 Administrators Posted December 11, 2004 clicky might be of some help Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
CryoEnix Posted December 11, 2004 Author Posted December 11, 2004 clicky might be of some help PlausiblyDamp, you're a star, a bloody star! From that code you've given me I've been able to make this function, I hope it helps other people like it helped me: Public Function GetMaskFromIP(ByVal TheIP As String) As String Dim mc As New Management.ManagementClass("Win32_NetworkAdapterConfiguration") Dim nics As Management.ManagementObjectCollection nics = mc.GetInstances() Dim nic As Management.ManagementObject For Each nic In nics If nic("ipEnabled") = True Then Dim s As String For Each s In nic("IPaddress") If s = TheIP Then Exit For Next If s <> TheIP Then GoTo TryNextIP s = "" For Each s In nic("IPSubnet") GetMaskFromIP = s Next End If TryNextIP: Next End Function Quote Chaos is merely logic beyond human comprehension
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.