my pc i p address RRS feed

All replies

  • To get the address(es) of the PC

            Dim strHostName As String = Net.Dns.GetHostName()
            Dim IPHostEnt As Net.IPHostEntry = Net.Dns.GetHostEntry(strHostName)
            For Each addr As Net.IPAddress In IPHostEnt.AddressList
                Debug.WriteLine("{0}  {1}", addr.AddressFamily, addr)

    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Friday, March 30, 2018 3:29 PM
  • Do you need the local IP address or the public IP address when behind NAT on a private network?

    Here is a class with static methods to get both.  The local address is gathered from the network adapter information instead of from DNS.  The public address is gathered from the API which is intended for this purpose.

    Public Class MyIP
        ''' <summary>
        ''' Gets the public IPv4 address for this computer as seen by the API.
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function GetPublicAddress() As Net.IPAddress
            Using client As New Net.WebClient
                Dim ipstring = client.DownloadString("")
                Dim result = Net.IPAddress.None
                Net.IPAddress.TryParse(ipstring, result)
                Return result
            End Using
        End Function
        ''' <summary>
        ''' Gets the first available IPv4 address on all active network adapters.
        ''' </summary>
        ''' <returns>An IPAddress instance containing the first available IPv4 address found, or IPAddress.None if no network adapters have an IPv4 address.</returns>
        Public Shared Function GetLocalAddress() As Net.IPAddress
            For Each adapter As Net.NetworkInformation.NetworkInterface In Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
                If adapter.Supports(Net.NetworkInformation.NetworkInterfaceComponent.IPv4) AndAlso
                     adapter.OperationalStatus = System.Net.NetworkInformation.OperationalStatus.Up AndAlso
                     Not adapter.NetworkInterfaceType = System.Net.NetworkInformation.NetworkInterfaceType.Loopback Then
                    For Each addr As Net.NetworkInformation.UnicastIPAddressInformation In adapter.GetIPProperties.UnicastAddresses
                        If addr.Address.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
                            Return addr.Address
                        End If
                End If
            Return Net.IPAddress.None
        End Function
    End Class

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, March 30, 2018 4:54 PM
  • what is the ip adress of my pc

    I believe one is also which is internal to the PC I believe.

    La vida loca

    Friday, March 30, 2018 7:29 PM
  • Hi,

    I'm afraid you need to specify what kind of IP address you want to know.

    [] is so-called "Local Loopback Address" which is fixed address and used for checking if NIC is working in a local computer.

    And a local computer has other kind of IP address. One is Local address (used in LAN) and the other is Public address (used in WAN).
    How to know Local/public addrss by code is already provided in the previous post.

    Ashidacchi --

    • Edited by Ashidacchi Friday, March 30, 2018 11:27 PM
    Friday, March 30, 2018 11:27 PM