【发布时间】:2015-08-13 08:21:48
【问题描述】:
我正在尝试检测连接到哪个网站的用户..
我尝试获取 tcp 连接并解析它们,例如我尝试检测 facebook。但是当我注销并关闭 facebook 时,它仍然显示 31.13.93.3(facebook 的 ip)
这是我的代码..
public partial class Form1 : Form
{
static string faceIP = "31.13.93.3";
static string _targetIP,_targetPORT,_connectedWebSiteIP,_connectedWebSitePORT = string.Empty;
static string[] splitted = null;
public Form1()
{
/* 127.0.0.1:5037:127.0.0.1:49569
* First = 127.0.0.1
* Second = 5037
* Third = 127.0.01
* Fourth = 49569
*/
InitializeComponent();
this.Name = "Active Tcp Connections";
if (findFacebookIP())
{
MessageBox.Show("You opened or connected to facebook page!");
}
}
public static bool findFacebookIP(){
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
foreach (TcpConnectionInformation c in connections)
{
string tcpCon = string.Format("{0}:{1}", c.LocalEndPoint.ToString(), c.RemoteEndPoint.ToString());
splitted = tcpCon.Split(':');
_targetIP = splitted[0]; // Main Machine ip adress / local ip address (First)
_targetPORT = splitted[1]; // Main machine port number (Second)
_connectedWebSiteIP = splitted[2]; // (Third)
_connectedWebSitePORT = splitted[3]; // (Fourth)
if (_connectedWebSiteIP == faceIP)
{
return true;
}
}
return false;
}
// face ip = 31.13.93.3
}
我还需要一直在后台运行它,因为此方法仅用于打开..您可以看到我在 Form1() 构造函数方法中编写了它。 感谢您的帮助。
【问题讨论】:
标签: c# network-programming ip-address detection