如何用c#获取wifi路由器信息 [英] how can get wifi router info with c#
问题描述
我会给出一个解释我问题的情况;
我们学校有很多wifi路由器。学校有这么多建筑。所以每个房间都有一个wifi路由器。每个学生都有一台电脑,我想通过wifi路由器的ID在我们学校制作一个定位系统。我将创建一个包含Rooters信息的数据库(哪个rooter在哪个房间)。稍后我将从其中一台PC获取有关它与rooter连接的信息。之后我会将该信息与数据库进行比较。所以我能够得到他的位置。因此,为了制作所有这些东西,我必须获得wifi路由器信息,尤其是路由器ID和名称。问题是如何用c#获取wifi路由器信息
我读过此MSDN示例 [ ^ ]开头:
< pre lang =c#> public static void ShowNetworkInterfaces()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface [] nics = NetworkInterface.GetAllNetworkInterfaces();
Console.WriteLine( {0}的接口信息。{1},
computerProperties.HostName,computerProperties.DomainName);
if (nics == null || nics.Length < 1 )
{
Console.WriteLine( 找不到网络接口。);
return ;
}
Console.WriteLine( 接口数量..... ...............:{0},nics.Length);
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties属性= adapter.GetIPProperties();
Console.WriteLine();
Console.WriteLine(adapter.Description);
Console.WriteLine( String .Empty.PadLeft(adapter.Description.Length,' < span class =code-string> ='));
Console.WriteLine( 接口类型............... ...........:{0},adapter.NetworkInterfaceType);
Console.WriteLine( 物理地址............... .........:{0},
adapter.GetPhysicalAddress()。ToString());
Console.WriteLine( 运行状态............... .......:{0},
adapter.OperationalStatus);
string versions = ;
// 为支持的IP版本创建显示字符串。
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
versions = IPv4;
}
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
if (versions.Length > 0 )
{
版本+ = ;
}
版本+ = IPv6;
}
Console.WriteLine( IP版本.......... ....................:{0},版本);
ShowIPAddresses(properties);
// 以下信息对环回适配器没用。
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
{
继续跨度>;
}
Console.WriteLine( DNS后缀.......... ....................:{0},
properties.DnsSuffix);
string 标签;
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();
Console.WriteLine( MTU ................ ......................:{0},ipv4.Mtu);
if (ipv4.UsesWins)
{
IPAddressCollection winsServers = properties.WinsServersAddresses;
if (winsServers.Count > 0 )
{
label = WINS服务器....... .....................:;
ShowIPAddresses(label,winsServers);
}
}
}
Console.WriteLine( DNS已启用.............................:{0},
properties.IsDnsEnabled );
Console.WriteLine( 动态配置的DNS .............. :{0},
properties.IsDynamicDnsEnabled);
Console.WriteLine( 仅接收............... .............:{0},
adapter.IsReceiveOnly);
Console.WriteLine( Multicast ................ ...............:{0},
adapter.SupportsMulticast);
ShowInterfaceStatistics(adapter);
Console.WriteLine();
}
I will give a situation to explain my question;
We have so many wifi router in our school. The school have so many building. So each room have a wifi router. Every students have a pc , i want to make a "Positioning System" in our school by taking wifi router's id. I am going to make a database that contains information about Rooters(Which rooter is in which room). Later on i will get information from one of the PCs about it's connection with rooter.after that i will compare that info with the database. So i wil be able to get his location. So for making all of this thing I have to get wifi router info especially router id and name. The question is "how can get wifi router info with c#"
I'd read this MSDN example[^] to start with:
public static void ShowNetworkInterfaces() { IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName); if (nics == null || nics.Length < 1) { Console.WriteLine(" No network interfaces found."); return; } Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length); foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); Console.WriteLine(); Console.WriteLine(adapter.Description); Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'=')); Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType); Console.WriteLine(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString()); Console.WriteLine(" Operational status ...................... : {0}", adapter.OperationalStatus); string versions =""; // Create a display string for the supported IP versions. if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { versions = "IPv4"; } if (adapter.Supports(NetworkInterfaceComponent.IPv6)) { if (versions.Length > 0) { versions += " "; } versions += "IPv6"; } Console.WriteLine(" IP version .............................. : {0}", versions); ShowIPAddresses(properties); // The following information is not useful for loopback adapters. if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback) { continue; } Console.WriteLine(" DNS suffix .............................. : {0}", properties.DnsSuffix); string label; if (adapter.Supports(NetworkInterfaceComponent.IPv4)) { IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties(); Console.WriteLine(" MTU...................................... : {0}", ipv4.Mtu); if (ipv4.UsesWins) { IPAddressCollection winsServers = properties.WinsServersAddresses; if (winsServers.Count > 0) { label = " WINS Servers ............................ :"; ShowIPAddresses(label, winsServers); } } } Console.WriteLine(" DNS enabled ............................. : {0}", properties.IsDnsEnabled); Console.WriteLine(" Dynamically configured DNS .............. : {0}", properties.IsDynamicDnsEnabled); Console.WriteLine(" Receive Only ............................ : {0}", adapter.IsReceiveOnly); Console.WriteLine(" Multicast ............................... : {0}", adapter.SupportsMulticast); ShowInterfaceStatistics(adapter); Console.WriteLine(); }
这篇关于如何用c#获取wifi路由器信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!