我们学校是每个宿舍两个网口,每个网口有固定的IP,一个宿舍常通过路由来上网,我想获得网口的IP,有什么办法么?

解决方案 »

  1.   

    开始 运行
    cmd
    ipconfig/all
    想办法得到里面的数据
      

  2.   

    我觉得有两个办法
    1是web登陆你的路由,得到它的IP,前提是路由设备可网管
    2是得到你自己的网关,按我的理解,你的网关和DNS都是路由的IP才对
    得到自己网关是完全可以做到的
      

  3.   

    是我理解错了,如果你的路由设备有DHCP,那更难得到路由上端的IP
    我的思路是这样:你可以写个路由跟踪的小功能,如果你的电脑直接接了路由器,路由器又直接接了你宿舍的网口,那你tracert的第2跳,就是你宿舍网口的地址,所谓第2跳不知道你是否理解,你机器是0,它的上个设备就是1,再上就是2
    我这有段代码,没经过测试,是路由跟踪的实现,你可以自己看下using System.Net;using System.Net.Sockets;//定义ICMP结构/
    //在构造ICMP包时,需要首先定义几个ICMP包用到的结构。 struct ICMPConstants { public const int ICMP_ECHOREPLY= 0;   public const int ICMP_TIMEEXCEEDED= 11;   public const int ICMP_ECHOREQ= 8;   public const int MAX_TTL= 256;   } //ICMP 包头 struct ICMP { public byte type;   public byte code;   public ushort checksum;  public ushort id;    public ushort seq;  // 次序 } // ICMP 应答请求 struct REQUEST { public ICMP m_icmp; public byte []m_data;}//函数CreatePacket
    //函数CreatePacket用来构造一个符合要求的ICMP数据包,具体实现如下:public static byte[] CreatePacket( REQUEST req ){ Byte[] ByteSend= new Byte[PACKET_SIZE+ 8];  ByteSend[0]= req.m_icmp.type;  ByteSend[1]= req.m_icmp.code;  Array.Copy(BitConverter.GetBytes(req.m_icmp.checksum), 0, ByteSend, 2, 2);  Array.Copy(BitConverter.GetBytes(req.m_icmp.id), 0, ByteSend, 4, 2);  Array.Copy(BitConverter.GetBytes(req.m_icmp.seq), 0, ByteSend, 6, 2); for(int i=0; i< req.m_data.Length; i++)  ByteSend[i+8]= req.m_data[i]; //计算校验和 int iCheckSum = 0; for (int i= 0; i < ByteSend.Length; i+= 2)   iCheckSum += Convert.ToInt32( BitConverter.ToUInt16(ByteSend,i));  iCheckSum = (iCheckSum >> 16) + (iCheckSum & 0xffff);  iCheckSum += (iCheckSum >> 16);  Array.Copy(BitConverter.GetBytes((ushort)~iCheckSum), 0, ByteSend, 2, 2); return ByteSend; }