本帖最后由 carbonincauc 于 2011-06-27 23:27:43 编辑

解决方案 »

  1.   

    你可以读注册表啊,在这个节点下
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Service\Tcpip\Parameters\Interfaces\
    这个底下根据你网卡的数量会有不同的子项类似于{307A0543-1269-4429-9C09-E104F08C5B59}这种GUID值,
    你遍历一下就可以了。
    IPAddress--IP
    DefaultGateway--网关
    SubnetMask--掩码
      

  2.   

    Request.ServerVariables.Get("Remote_Addr").ToString()
      

  3.   

    今天查了资料 和你说的方法一致,但是我又发现了很多问题,可以获得IP地址,但是我改如何区分哪个网卡是无线网卡,哪个是有线网卡,并且还有一些虚拟网卡,当然我的电脑上我能自己区分,但是软件移植到其他地方又该怎么区分呢?RegistryKey     reg=Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services\Tcpip\Linkage");
           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地址呢?