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


    Return IP
End Function

Tagged with ip, address, network.


By jangelnunez, 9/13/2014
Yes, ┬┐But how can i get the provider?
By Koopakiller, 10/2/2014
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

Log in, to comment!