Specifying A Value For Local IPs

Joined
Jun 28, 2007
Messages
6
Location
/etc/passwd
Programming Experience
5-10
I've basically finished a program I have recently started, and so at this point I am just fine-tuning everything and "dressing up" the program a bit before deployment. My question is regarding getting the local IP of the computer in IPv4 format. I've read a few snippets of code using loops to list all of them, but I'm after the usual 192.*.*.* IP scheme.
In my tests I'm using "Dns.GetHostAddresses(Dns.GetHostName)(3).ToString", which outputs 192.168.1.47. In some of the other examples I've read people suggest using a value of 0, which displays the information in a different format on my computer. If I use the current line keeping the value of 3 will this appear differently on others' computers, or can it stay this way?
 
Why do you need it to be IPv4 format? Btw you can iterate and check AddressFamily like this:
VB.NET:
    Function getLocalIPv4() As Net.IPAddress
        For Each ip As Net.IPAddress In Net.Dns.GetHostAddresses("")
            If ip.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                Return ip
            End If
        Next
        Return Nothing
    End Function
From Dns.GetHostAddresses Method documentation remarks:
When an empty string is passed as the host name, this method returns the IPv4 addresses of the local host for all operating systems except Windows Server 2003; for Windows Server 2003, both IPv4 and IPv6 addresses for the local host are returned.
 
Thank you very much, JohnH. The only reason I want IPv4, and not IPv6, is because the code is not going to serve a true purpose other than being included in an optional data report. I figured I could loop through them, but was not sure if there was any parameter I could specify to make sure it was IPv6 other than analyzing the string. Thank you again for your help.
 
Back
Top