Download presentation
Presentation is loading. Please wait.
1
Socket Programming--Traceroute
Jonathan
2
Step 1 Turn a hostname into an IP address.
Input dest_name and gethostbyname() this funtion will turn hostname into IP address.
3
Step 2 Create Sockets for connection
UDP uses to send data, it requires datagram socket(SOCK_DGRAM). Icmp packets send back datas, it requires raw socket(SOCK_RAW).
4
Step 3 Set TTL TTL begins with 1 and it will plus one in each loop.Use setsockopt() to set the TTL.
5
Step 4 Bind sockets and send packets
bind() function uses to receive data by the port and hostname store in empty string. sendto() function uses to send empty string to dest_name.
6
Step 5 Get IP address, Turn IP address and print the data
recvfrom() function takes IP address , its block size is 512. And we close the both sockets. After get IP address, I use gethostbyaddr() function to get its hostname, if it doesn’t have hostname, its address equal to its hostname. After I get hostname, printout the data. If curr_addr =None, it will print “*”.
7
Step 6 Break the loop The loop will stop when curr_addr = dest_name or ttl > max_hops. Then my program will ask you if you want to traceroute another host or not.
8
Python 2 V.S. Python 3
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.