3

我正在使用 C# 编写一个 Windows 应用程序,我需要在其中检测网络位置类型。

当您将 Windows 机器连接到网络(有线或无线)时,它会尝试识别网络,然后将其分类为公共、私有等。我想使用我的应用程序以编程方式做同样的事情。我怎么做?

如果需要其他详细信息,请告诉我。谢谢你。

4

2 回答 2

0

你需要做两件事:

  • 解析本地机器的IP地址。这本身就是一个挑战,因为通常机器会有多个 IP 地址。它可以同时使用多个IP。IP 地址可能(并且正在)动态变化

  • 检查 IP 地址是否在私有范围内。有关链接和更多信息,请参阅此答案。实际上,每个私有地址只能在本地网络 - LAN 内路由。无法从外部连接到私有地址。如果机器想与外界对话,它使用网关机器。网关机器记住请求的来源(私有 IP)将其转换为公共 IP 并解析反向响应。

于 2013-05-03T19:55:37.570 回答
-1
  you networkinterface to get the network information  
  NetworkInterface[] interfaces =  NetworkInterface.GetAllNetworkInterfaces();


  it has many properties and the output showing infornt of that

  NetworkInterface[0].Description:  Intel(R) 82579LM Gigabit Network Connection
  NetworkInterface[0].ID: {xxxxxxxxxx-0322-466Fxxx-xxxxxxxxxx}
  NetworkInterface[0].Name: Ethernet
  NetworkInterface[0].Interface Type: Ethernet
  NetworkInterface[0].Operational Status: Down
  NetworkInterface[0].Speed: -1
  NetworkInterface[0].Supports Multicast: True
于 2013-05-03T19:54:52.847 回答