Click here to Skip to main content
15,113,225 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have a static IP address for a modem. I need to get the IP address of the modem using C# code? Can you help me by giving any ideas?

Thanks in advance,
Saranya1388
Posted
Updated 30-Dec-10 1:32am
v2
Comments
sjelen 30-Dec-10 8:55am
   
Do you mean public static internet IP of your modem or LAN static IP of your modem?
In first case, look at second part of "Answer 2" - that's probably the easiest way.

Maybe one of these answers can help[^].
   
have you tried with this

C#
var name = Dns.GetHostName();
var entry = Dns.GetHostEntry(name);
foreach (var address in entry.AddressList) {
   Console.WriteLine(address);
}



If still you are not convinces then have a look onto this as well

string ip = System.Net.WebClient.DownloadString("http://whatismyip.org/");
   
Comments
maq_rohit 31-Dec-10 8:50am
   
See When you are using dial-up(Modem), it uses PPP and if connection is assigned a public IP-adress. So the code(2nd part) above returns the same IP address as http://whatismyip.org/. For getting public Ip address you have to call connection from web. There is no way in c# to get public ip (Assume you have dynamic ip in modem) without internet connection

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




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