- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
#!/usr/bin/env python3
import sys
import socket
def main():
if len(sys.argv) != 2:
print("Программа ожидает 1 аргумент: доменное имя хоста")
return 1
# Input.
host_name = sys.argv[1]
print(f"Доменное имя хоста: {host_name}")
host_ip = socket.gethostbyname(host_name)
print(f"IP-адрес хоста: {host_ip}")
host_port = 33433
timeout = 2 # Seconds.
receiving_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
receiving_socket.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
receiving_socket.settimeout(timeout)
receiving_socket.bind(("", host_port))
sending_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sending_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
received_ip = None
current_hop = 1
max_hop = 100
while received_ip != host_ip and current_hop < max_hop:
sending_socket.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, current_hop)
sus = True
for i in range(7):
try:
sending_socket.sendto(bytes(str(current_hop), 'utf-8'), (host_ip, host_port))
data, addr = receiving_socket.recvfrom(1)
if addr:
received_ip = addr[0]
print(f"hop: {current_hop} -> {received_ip}")
sus = False
break
else:
raise "sus"
except:
continue
if sus:
print(f"hop: {current_hop} -> *")
current_hop += 1
if __name__ == "__main__":
main()
Что-то я давно не заходил... был занят, писал утилиту. Лицензия – «MIT».
JloJle4Ka 18.12.2022 11:28 # 0
Soul_re@ver 18.12.2022 11:41 # 0
bootcamp_dropout 18.12.2022 12:45 # 0
Desktop 18.12.2022 13:10 # 0
bootcamp_dropout 18.12.2022 16:16 # 0
Gorbatokalodoev 18.12.2022 17:05 # 0
Desktop 18.12.2022 13:43 # 0
DaveMustAim 19.12.2022 06:32 # 0
Gorbatokalodoev 19.12.2022 20:57 # 0