简体   繁体   English

如何获得3G调制解调器的IP地址?

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

My GPRS modem has got a sim card. 我的GPRS调制解调器有一张SIM卡。 it can connect Web. 它可以连接Web。 Web service give it a ip number. Web服务给它一个ip号码。 i need it. 我需要它。 like that: http://www.your-ip-address.com/ 像这样: http : //www.your-ip-address.com/

How can i do that C#? 我该怎么做C#?

You can use the static method WebClient.DownloadString(url) to read your external IP address from any web service providing such data: 您可以使用静态方法WebClient.DownloadString(url)从任何提供此类数据的Web服务中读取您的外部IP地址:

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. 如果要在生产环境中使用此功能,则最好确保所指向的URL在应用程序的整个生命周期中始终存在。 The best way is probably to host the web service yourself. 最好的方法可能是自己托管Web服务。

Also, you should add some error checking around this code, as it will fail if the internet connection or the web service is unavailable. 另外,您应该在此代码周围添加一些错误检查,因为如果Internet连接或Web服务不可用,它将失败。

You can create a WebRequest to http://whatismyip.com/automation/n09230945.asp which houses only your IP address 您可以创建一个WebRequest到http://whatismyip.com/automation/n09230945.asp ,其中仅包含您的IP地址

Start here 这里开始

You can get a list of your IP addresses via DNS using the following code: 您可以使用以下代码通过DNS获取IP地址列表:

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 . 如果要将IP地址作为硬件的属性,则可以使用名称为Win32_NetworkAdapterConfigurationSystem.Management.ManagementClass See http://msdn.microsoft.com/en-us/library/system.management.managementclass.aspx for details. 有关详细信息,请参见http://msdn.microsoft.com/zh-cn/library/system.management.managementclass.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM