Results 1 to 14 of 14

Thread: VB.Net Simple function to get external IP-adress

Threaded View

  1. #1

    Thread Starter
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Cool VB.Net Simple function to get external IP-adress

    This is The Code
    Code:
    Imports System.Net
    Imports System.Text.RegularExpressions
    
     Function GetExternalIP() As IPAddress
            Dim lol As WebClient = New WebClient()
            Dim str As String = lol.DownloadString("http://www.ip-adress.com/")
            Dim pattern As String = "<h2>My IP address is: (.+)</h2>"
            Dim matches1 As MatchCollection = Regex.Matches(str, pattern)
            Dim ip As String = matches1(0).ToString
            ip = ip.Remove(0, 21)
            ip = ip.Replace("</h2>", "")
            ip = ip.Replace(" ", "")
            Return IPAddress.Parse(ip)
        End Function
    This is How to use it

    Code:
     Dim MyIP As IPAddress = GetExternalIP()
    This code is an easy method to get your Ip-address. I've read that sites disclaimer and all the fine print and nothing said I'm not allowed to parse it's html code, although I'm not sure if their is a daily limit or not

    This is my first code bank submission and I hope that it will help someone out
    I did a search and didn't find something similar
    Last edited by BlindSniper; Jan 6th, 2011 at 08:09 AM. Reason: added Imports

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width