ruby - Why can't I receive an ICMP Message? -
i want make simple traceroute without library.
in wireshark see incoming response, can't receive message. port receive_socket
same port send_socket
, , protocols specified should correct.
def traceroute local_host = '0.0.0.0' remote_host = '8.8.8.8' traceroute_port = 33434 random_port = rand(10000..20000) # create udp-socket udp_socket = udpsocket::new udp_socket.bind(local_host, random_port) udp_socket.setsockopt( 0, socket::ip_ttl, 3) # send data udp_socket.connect(remote_host, traceroute_port) udp_socket.send('traceroute', 0) # create receive-socket receive_socket = socket.open(socket::pf_inet, socket::sock_raw, socket::ipproto_icmp) receive_socket.bind(socket.pack_sockaddr_in(random_port, local_host)) # receive data begin p receive_socket.recvfrom(1024) rescue socketerror => exception puts exception.message end end
it great if somone can me out.
Comments
Post a Comment