解决方案 »
- 大家帮我看一段代码~~这段提示的错误是 未将对象引用设置到对象的实例
- 求助!在 System.Runtime.InteropServices.COMException 中第一次偶然出现的“mscorlib.dll”类型的异常
- c#从ACCESS数据库中读取数据在DATAGRIDVIEW中显示后,如何写入EXCEL中?
- .net中进程之间的的编程
- 请问MS Studio.NET 2005的FrameWork版本号?
- 请教一下,我怎么复制一下table的结构给一个新的表。我不要复制数据。
- c#中ODBC连接sybase时的并发问题,内有详细描述,请大家帮助
- 请教C#中调用API的问题(续)
- 急:请教TreeView的用法!
- WinForm中DataGridView使用问题请教
- dropdownlist绑定数据后如何能将显示置空
- 查询SQL Server表数据,使用不同的方法返回结果集。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Service\Tcpip\Parameters\Interfaces\
这个底下根据你网卡的数量会有不同的子项类似于{307A0543-1269-4429-9C09-E104F08C5B59}这种GUID值,
你遍历一下就可以了。
IPAddress--IP
DefaultGateway--网关
SubnetMask--掩码
string[] str = (String[])reg.GetValue("Route");
string asd = str[6].Substring(1, str[0].Length - 2);//此处的6是我的有线网卡
string path=@"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"+asd;
RegistryKey reglp = Registry.LocalMachine.OpenSubKey(path);
string []strip = (string[])reglp.GetValue("IPAddress", "NULL", RegistryValueOptions.None);
//string[] strip=(string[])reglp.GetValue("IPAddress");
this.label1.Text = strip[0];
但是我想通过Software\Microsoft\Windows NT\CurrentVersion\NetworkCards下属的各个键值来读取各网卡的信息(这样可以有效的屏蔽很多虚拟网卡)
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\NetworkCards\8");
string str = (String)reg.GetValue("ServiceName");
string asd = str.Substring(1, str.Length - 2);
string path=@"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"+"{"+asd+"}";
RegistryKey reglp = Registry.LocalMachine.OpenSubKey(path);
string []strip = (string[])reglp.GetValue("IPAddress", "NULL", RegistryValueOptions.None);
this.label1.Text = strip[0];
但是在Software\Microsoft\Windows NT\CurrentVersion\NetworkCards有两个树枝“8”,“12”,但是我又发现我同学的电脑里面是“8”,“13”,两台电脑都有两个网卡 而且两个网卡的厂家不一样,我该如何获得我指定网卡的IP地址呢?