1
명백하게 ICMP가 Traceroute를 만드는 유일한 방법은 아닙니다. This 및 this 답변은 TTL이 낮은 UDP 패킷 (또는 기타)을 보내고 ICMP 메시지를 기다릴 수 있음을 나타냅니다.UDP를 사용하여 Traceroute를 구현하려면 어떻게해야합니까?
C#으로 구현하려면 어떻게해야합니까? System.IO.Sockets? TCP 개체는 무엇입니까? 누구나 쉬운/최선의 방법을 알고 있습니까?
업데이트 1 :
다음 코드는 TTL이 명중 할 때 제대로 예외를 던질 것으로 보인다. 반환 된 UDP 패킷에서 어떻게 정보를 추출합니까?
어떻게 내가 받고있어 UDP 패킷이 나를위한 것입니다 것을 알고 (내 호스트하지 다른 응용 프로그램?)
public void PingUDPAsync(IPAddress _destination, short ttl)
{
// This constructor arbitrarily assigns the local port number.
UdpClient udpClient = new UdpClient(21000);
udpClient.Ttl = ttl;
// udpClient.DontFragment = true;
try
{
udpClient.Connect(_destination, 21000);
// Sends a message to the host to which you have connected.
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
udpClient.Send(sendBytes, sendBytes.Length);
//IPEndPoint object will allow us to read datagrams sent from any source.
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
// Blocks until a message returns on this socket from a remote host.
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
// Uses the IPEndPoint object to determine which of these two hosts responded.
Console.WriteLine("This is the message you received " +
returnData.ToString());
Console.WriteLine("This message was sent from " +
RemoteIpEndPoint.Address.ToString() +
" on their port number " +
RemoteIpEndPoint.Port.ToString());
udpClient.Close();
}
catch (SocketException socketException)
{
Console.WriteLine(socketException.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}