Ciao, sto cercando di realizzare un semplice traceroute usando i pacchetti udp e icmp di ritorno, putroppo il programma si blocca (resta fermo) al momento della ricezione degli icmp. Ho già provato a impostare windows firewall consentendo ogni protocollo in ingresso al programma, ma niente. Eppure utilizzando wireshark il primo pacchetto icmp arriva. E' un problema nel codice oppure un problema delle raw socket windows o del firewall?
codice:
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Dim tt As Short
Dim udpClient As New UdpClient(11000)
Dim rawSocket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("prova")
Dim receive(256) As Byte
tt = 1
rawSocket.Bind(RemoteIpEndPoint)
Try
While tt<=30
udpClient.Ttl = tt
udpClient.Send(sendBytes, sendBytes.Length, "google.it", 5005)
rawSocket.ReceiveFrom(receive, RemoteIpEnd)
Dim returnData As String = Encoding.ASCII.GetString(receive)
Console.WriteLine(RemoteIpEndPoint.Address.ToString())
If RemoteIpEndPoint.Address.ToString = "216.58.198.35" Then
Exit While
End If
tt = tt + 1
End While
udpClient.Close()
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub
End Module