我編寫了一個類似於嗅探器的應用程序,它可以在端口上偵聽並向用戶顯示在您的計算機和Internet之間傳輸的信息,如源和目標ip。寫端口監聽器
我該如何改變它來檢索url地址而不是ip地址有可能嗎? 我使用套接字工作。
private byte[] byUDPData = new byte[4096]; //Data carried by the UDP packet
public UDPHeader(byte [] byBuffer, int nReceived)
{
MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
BinaryReader binaryReader = new BinaryReader(memoryStream);
//The first sixteen bits contain the source port
usSourcePort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the destination port
usDestinationPort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the length of the UDP packet
usLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//The next sixteen bits contain the checksum
sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
//Copy the data carried by the UDP packet into the data buffer
Array.Copy(byBuffer,
8,
byUDPData,
0,
nReceived - 8);
}
您必須重新組裝應用程序級別的數據並從HTTP請求中提取URL。這是一項非常大的工作(因爲您必須複製幾個協議層的功能),並且您應該認真考慮調整(或使用)現有工具。你的問題是:「我有一把錘子和一些2x4s,我想建一座吊橋。」 – 2012-03-03 11:34:36
重要的事實是,http不會運行udp ... – 2012-03-03 13:37:13