ctw6av
(usa Nenhuma)
Enviado em 28/11/2016 - 20:04h
Peguei este código na internet e adaptei para sua necessidade, está bem simples de ler e se passar de 50 hosts ele vai apontar uma mensagem de falha na conexão.
O output do comando apontando para o Vol:
1 gateway 192.168.1.1
2 Oi-Los10-cpce-ms-a1k-01.brasiltelecom.net.br 221.10.196.73
3 BrT-G0-0-0-2-cpces-ms-rotd-xr01.brasiltelecom.net.br 220.199.193.233
4 BrT-G6-1-3-etces-df-rotn-j01.brasiltelecom.net.br 200.199.193.24
5 te-0-0-0-1-ETCE-DF-ROTB-01.brasiltelecom.net.br 177.2.192.102
6 162-144-34-172.unifiedlayer.com 162.144.34.172
O código:
#!/usr/bin/python3
import socket
import struct
def main(destination):
destination_addr = socket.gethostbyname(destination)
port = 33434
max_hops = 50
icmp = socket.getprotobyname('icmp')
udp = socket.getprotobyname('udp')
ttl = 1
while True:
recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
# Build the GNU timeval struct (seconds, microseconds)
timeout = struct.pack("ll", 5, 0)
# Set the receive timeout so we behave more like regular traceroute
recv_socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeout)
recv_socket.bind(('', port))
print('{:<4}'.format(ttl), end='')
send_socket.sendto(''.encode(), (destination, port))
curr_addr = None
curr_name = None
finished = False
tries = 3
while not finished and tries > 0:
try:
_, curr_addr = recv_socket.recvfrom(512)
finished = True
curr_addr = curr_addr[0]
try:
curr_name = socket.gethostbyaddr(curr_addr)[0]
except socket.error:
curr_name = curr_addr
except socket.error:
tries -= 1
print("* ")
send_socket.close()
recv_socket.close()
if not finished:
pass
if curr_addr is not None:
curr_host = '{:<70} {:<50}'.format(curr_name, curr_addr)
else:
curr_host = ''
print('{}'.format(curr_host))
ttl += 1
if curr_addr == destination_addr:
break
if ttl > max_hops:
print('Não foi possível estabelecer uma conexão.')
break
if __name__ == "__main__":
main('www.vivaolinux.com.br')
______________________________________________________________________
OS: Biebian
Kernel: x86_64 3.5.2-amd64
Resolution: 1320x768
CPU: Intel Core i3-4005U CPU @ 1.7GHz
RAM: 3852MiB
Distro:
http://biebian.sourceforge.net/