2013-05-03 63 views
3

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

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

请让我知道是否需要额外的细节。谢谢。

回答

0
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 
0

您需要做两件事情:本地计算机的

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

  • 检查IP地址是否在专用范围内。有关链接和更多信息,请参阅this answer。实际上,每个私有地址只能在本地网络 - 局域网内路由。从外部连接到私人地址是不可能的。如果机器想要与外界通话,它使用网关机器。网关机器会记住请求来自哪里(私有IP)将其转换为公共IP并解决相反的响应。

相关问题