I can't find any working code to get the external IP address of the computer. Could anyone give me a snippet of code to do this please.
Asked
Active
Viewed 4,697 times
0
-
Unfortunately there's no standard way to get that - even your computer doesn't know your external IP address. You'd have to use an external service. [See this related question](http://stackoverflow.com/questions/3097589/getting-my-public-ip-via-api). – Kenney Dec 05 '15 at 20:44
-
@Kenney I was hoping someone could give me the code to do it even using an external service. – Man16 Dec 05 '15 at 20:53
-
[See this question about making HTTP request in vb.net](http://stackoverflow.com/questions/14835916/curl-command-to-html-or-vb-net). – Kenney Dec 05 '15 at 21:06
1 Answers
2
This will work for you, although it's functioning depends on this remote page being available. If it goes down, this function stops working. You could then just point it somewhere else.
''' <summary>
''' Returns your IP address as string
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function IpAddress() As String
Using wc As New Net.WebClient
Return System.Text.Encoding.UTF8.GetString(wc.DownloadData("http://tools.feron.it/php/ip.php"))
End Using
End Function

b.pell
- 3,873
- 2
- 28
- 39
-
Seems to work. I'm a little concerned about the stability of this address. – pianocomposer Apr 21 '21 at 18:33
-
@user1000008 That's a legitimate concern. The page it contacts just needs to return an IP as a string. This could be a site of yours, it just has to exist to see where the public request is coming from. – b.pell Apr 21 '21 at 18:57
-
The service address is going to change to https://ip.feron.it, it's already alive. The old one will go dow any time soon – Luc Jun 08 '23 at 20:33