VB - Get own internet IP address

By , 4/8/2008
(1 ratings)
This function is able to read out your own IP address you got assigned from your internet provider. Even if you are using a router. This works because the function sends a request to a website which contains your IP address.
Public Function GetExternalIP(ByVal Provider As String) As String
    Dim WebReq As HttpWebRequest = HttpWebRequest.Create(Provider)
    Dim WebRes As HttpWebResponse = WebReq.GetResponse()

    Dim ResStream As System.IO.Stream = WebRes.GetResponseStream
    Dim ResStreamReader As New StreamReader(ResStream, Encoding.UTF8)

    Dim IP As String = ResStreamReader.ReadToEnd

    ResStream.Close()
    WebRes.Close()

    Return IP
End Function

Tagged with ip, address, network.

2 Comments

By jangelnunez, 9/13/2014
Yes, ┬┐But how can i get the provider?
By Koopakiller, 10/2/2014
@jangelnunez
You need some service like http://checkip.dyndns.org/, but it is not so simple to get an IP adress from a html code.
There are much better ways, see
http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c
 

Log in, to comment!