Get IP and show in the label RRS feed

  • Question

  • I need a line which get the IP address which is given by internet, and show it in the label.
    Saturday, May 5, 2018 10:14 AM

All replies

  • You can do that with WMI 

    Here a tool to create code therefore


    Saturday, May 5, 2018 10:17 AM
  • How to use this?
    Saturday, May 5, 2018 10:20 AM
  • I just need a code, which would get an IP, and show it to label.
    Saturday, May 5, 2018 10:21 AM
  • I just need a code, which would get an IP, and show it to label.
    did you try that tool, it makes the code


    Saturday, May 5, 2018 11:39 AM
  • I don't know how to use it, i just started my first project few days ago ;/
    Saturday, May 5, 2018 11:46 AM
  • See IPAddress Class for various code. Also see How To Get All Network Information in for another example.

    In this code I used NetStat with -r argument to retrieve "the contents of the IP routing table. This is equivalent to the route print command.".

    Also your IP address will probably not be a WAN IP address unless you purchase a Static WAN IP address from your ISP. Instead you will be off a local LAN from your ISP and have a local rather than WAN IP address. So it's not like you can get this address and a friend get theirs and suddenly you can communicate directly with each other via the internet.

    Option Strict On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            TextBox1.Font = New Font("Consolas", 11)
            TextBox1.ScrollBars = ScrollBars.Both
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim NetstatInfo4 As New ProcessStartInfo
            NetstatInfo4.FileName = "C:\Windows\System32\Netstat.exe"
            NetstatInfo4.Arguments = ChrW(34) & "-r" & ChrW(34)
            NetstatInfo4.CreateNoWindow = True
            NetstatInfo4.UseShellExecute = False
            NetstatInfo4.RedirectStandardOutput = True
            Dim p4 As Process = Process.Start(NetstatInfo4)
            Dim IFaceListAndRoutes As New List(Of String)
            Do Until p4.StandardOutput.EndOfStream
                Dim Outputs As String = p4.StandardOutput.ReadLine
            Dim Result As String = ""
            For i = 0 To IFaceListAndRoutes.Count - 1
                If IFaceListAndRoutes(i).Contains(" ") Then
                    Result = IFaceListAndRoutes(i)
                End If
            Result = Result.Replace(" ", "*|")
            Result = Result.Replace("|*", "")
            Result = Result.Replace("*", "")
            Dim Results() As String = Result.Split("|"c)
            TextBox1.AppendText("Your Network Gateway is - " & Results(3) & vbCrLf & "Your IP address is - " & Results(4))
        End Sub
    End Class

    La vida loca

    Saturday, May 5, 2018 7:50 PM
  •     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

    This uses a free service intended for this purpose.

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

    • Proposed as answer by Devon_Nullman Tuesday, May 8, 2018 7:37 PM
    Sunday, May 6, 2018 1:54 PM
  • I don't know how to use it, i just started my first project few days ago ;/

    You should mention what your first project is really so others can assist you better.

    La vida loca

    Sunday, May 6, 2018 3:04 PM
  • Hi GeyBen420,

    To get your Internet IP address when connected through router, we must use external service from

     Private Function GetComputer_InternetIP() As String
            Dim request As WebRequest = WebRequest.Create("")
            Dim response As WebResponse = request.GetResponse()
            Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
            'request.Proxy = Nothing
            Dim ipAddress As String = stream.ReadToEnd()
            Return ipAddress.Replace("<html><head><title>Current IP Check</title></head><body>Current IP Address: ", String.Empty).Replace("</body></html>", String.Empty)
        End Function
    Private Sub FrmAutoNumbers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim ipaddress = GetComputer_InternetIP()
        End Sub

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, May 7, 2018 6:06 AM