Click here to Skip to main content
14,932,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to know how to get the public IP without slowing down the device. It will be better if there is no need of using any websites as I think that slows down the application like around 10 seconds.

What I have tried:

I have used Net.Webclient with Downloadstring. But that is not a great option even though I get the IP result.
Posted
Updated 22-Jul-18 22:52pm

It looks like you want to detect the WAN IP address assigned to the router by your ISP (Internet Service Provider).

The common method(s) you have already tried partially are connecting to a server that returns the required information. That may be either a specific service for such purposes like whatismyip.com or a protocol that returns this information. But these may require some time, be not accessible anymore / temporarily, and are even wrong when using a proxy server located outside your local net.

Because the WAN IP is not changing often, you can use one of the above methods and avoid blocking of your application by doing it in a background thread.

The only reliable method requires that your application has access to the router (e.g. via Telnet, SSH or web interface, access from LAN is enabled, and your application knows the login credentials) and that the router provides an option to query this information (which depends on the router model).

Most routers write such information also to a log file. It would be then suficient to get and parse that log file.
   
Comments
Member 13857021 24-Jul-18 20:40pm
   
This can only work for one computer with the knowledge of router username and password. I am looking for a common solution.
Jochen Arndt 25-Jul-18 2:48am
   
A common solution has to create a connection to an external service which returns the information. If you care for speed, write your own service that simply replies with the IP address and host it somewhere. That should be much faster than a HTTP based service.
Member 13857021 26-Jul-18 2:41am
   
I have tried the HTTP one with backgroundworker. That is faster.
Use the IPAddress class:

IPAddress Class (System.Net)[^]
   
Comments
Member 13857021 23-Jul-18 22:47pm
   
Could you please provide an example as I am not getting any idea on how to use the class.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900