How can I retrieve the local machine hostname and Internet IP address using VB.NET | find External IP Address in VB.NET

How can I retrieve the local machine hostname and Internet IP address using VB

STEP 1: Get the Internet IpAddress(Using www.whoer.net Website)
STEP 2: Create Free Access Accounts of www.ipstack.com site.

i tried this code... but it returned my internal IP Address, Details...
Dim Sstring() As String = Nothing
        Try
            Dim systemName As String = System.Net.Dns.GetHostName().ToString.ToUpper
            Dim MyIP As String = GetExternalIP()


            Dim wrGETURL As WebRequest
            wrGETURL = WebRequest.Create("http://api.ipstack.com/" & MyIP & "?access_key=*******")

            Dim myProxy As New WebProxy("myproxy", 80)
            myProxy.BypassProxyOnLocal = True
            'wrGETURL.Proxy = myProxy
            wrGETURL.Proxy = WebProxy.GetDefaultProxy()

            Dim objStream As Stream
            objStream = wrGETURL.GetResponse.GetResponseStream()

            Dim objReader As New StreamReader(objStream)
            Dim sLine As String = ""
            Dim i As Integer = 0


            sLine = objReader.ReadLine
            Sstring = sLine.Split(",")

        Catch ex As Exception
        End Try
'VB.Net function to get external IP-adress
Function GetExternalIP() As String
        Dim Sip() As String = Nothing
        Try
            Dim lol As WebClient = New WebClient()
            Dim str As String = lol.DownloadString("https://whoer.net/")
            Dim pattern As String = "<strong data-clipboard-target="".your-ip"" class=""your-ip"" title=""Copy to clipboard"">(.+)</strong>"
            Dim matches1 As MatchCollection = Regex.Matches(str, pattern)
            Dim ip As String = matches1(0).ToString
            ip = ip.Remove(0, 21)
            ip = ip.Replace("</strong>", "")
            ip = ip.Replace(" ", "")
            Sip = ip.Split(">")
            Return Sip(1)
        Catch ex As Exception
            Sip = Nothing
        End Try
    End Function
Sample Screen shot:


Post a Comment

0 Comments