How can i get IP Address of my 3G modem?

爱⌒轻易说出口 提交于 2019-12-24 02:23:32

问题


My GPRS modem has got a sim card. it can connect Web. Web service give it a ip number. i need it. like that: http://www.your-ip-address.com/

How can i do that C#?


回答1:


You can get a list of your IP addresses via DNS using the following code:

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

If you want the IP address as a property of the hardware, you can use the System.Management.ManagementClass with the name Win32_NetworkAdapterConfiguration. See http://msdn.microsoft.com/en-us/library/system.management.managementclass.aspx for details.




回答2:


You can use the static method WebClient.DownloadString(url) to read your external IP address from any web service providing such data:

string ip = System.Net.WebClient.DownloadString("http://whatismyip.org/");

If you are going to use this in a production environment, better make sure that the URL you are pointing to, is guaranteed to stay around for the entire lifespan of your application. The best way is probably to host the web service yourself.

Also, you should add some error checking around this code, as it will fail if the internet connection or the web service is unavailable.




回答3:


You can create a WebRequest to http://whatismyip.com/automation/n09230945.asp which houses only your IP address

Start here



来源:https://stackoverflow.com/questions/2272483/how-can-i-get-ip-address-of-my-3g-modem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!