Click here to Skip to main content
12,825,743 members (38,075 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


16 bookmarked
Posted 3 Sep 2012

Getting the External IP Address

, 3 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A very simple and short way to get the external IP address


We connect to servers that give us our external IP address and try to parse the IP from returning HTML pages. But when servers make small changes on these pages or remove them, these methods stop working properly.

Here is a method that takes the external IP address using a server which has been alive for years and returns a simple response rapidly...


private string getExternalIp()
        string externalIP;
        externalIP = (new WebClient()).DownloadString("");
        externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
        return externalIP;
    catch { return null; }


Private Function GetExternalIp() As String
        Dim ExternalIP As String
        ExternalIP = (New WebClient()).DownloadString("")
        ExternalIP = (New Regex("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) _
        Return ExternalIP
        Return Nothing
    End Try
End Function


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Huseyin Atasoy
Turkey Turkey
I am interested in artificial intelligence, signal processing, electronics, robotics and internet/network technologies.

A few of my works:
KANO (Real-time Optical Mark Recognition)
Real-time object recognition
Real-time facial expression recognition

My blog

You may also be interested in...


Comments and Discussions

QuestionHow to obtain wan ip of two or more network adapters Pin
ggdppt20-Sep-15 5:31
memberggdppt20-Sep-15 5:31 
Questionnice post Pin
sun_ak4710-Sep-15 2:21
membersun_ak4710-Sep-15 2:21 
SuggestionWay without REGEX Pin
Rhodderz2-Mar-15 6:00
memberRhodderz2-Mar-15 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 3 Sep 2012
Article Copyright 2012 by Huseyin Atasoy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid