关于如何获取网吧IP的问题。
我写了个小东东,帮助捕获指定网卡的数据传输。我在家里和公司的机子上装了都能用。可是有朋友拿到网吧用,就不能用了。是不是网吧的机子有什么特殊的设置?
如果是动态分配,但也应该可以检测出来嘛。有一家网吧显示IP为:0.0.0.61 ,但一点开始绑定,就弹出 "在其上下文中,请求的地址无效"的错误提示。
哪位大侠能帮助解释一下。如何解决这个问题。谢谢。
代码如下:
获取IP列表:
IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
if (HosyEntry.AddressList.Length > 0)
{
int i = 1;
foreach (IPAddress ip in HosyEntry.AddressList)
{
sIPList.Add(ip.ToString());
this.cbox_IP.Items.Add(ip.ToString());
i++;
}
}
绑定IP:
if (!bContinueCapturing)
{
//Start capturing the packets...
//btnStart.Text = "&Stop";
bContinueCapturing = true;
//For sniffing the socket to capture the packets has to be a raw socket, with the
//address family being of type internetwork, and protocol being IP
mainSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Raw, ProtocolType.IP);
//Bind the socket to the selected IP address
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(CaptureIPAddress), 0));
//Set the socket options
mainSocket.SetSocketOption(SocketOptionLevel.IP, //Applies only to IP packets
SocketOptionName.HeaderIncluded, //Set the include the header
true); //option to true
byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
byte[] byOut = new byte[4] { 1, 0, 0, 0 }; //Capture outgoing packets
//Socket.IOControl is analogous to the WSAIoctl method of Winsock 2
mainSocket.IOControl(IOControlCode.ReceiveAll, //Equivalent to SIO_RCVALL constant of Winsock 2
byTrue,
byOut);
//Start receiving the packets asynchronously
mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
new AsyncCallback(OnReceive), null);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "小工具", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
[解决办法]
网吧一般都装了网管软件,应该和这个有一点关系.
[解决办法]
网管软件真有可能有关系
[解决办法]
要穿过网吧的“防火墙”
[解决办法]
看看NAT网络穿透技术,哈哈
[解决办法]