Download presentation
Presentation is loading. Please wait.
1
Socket Programming--Traceroute
Jonathan
2
ICMP(Internet Control Message Protocol)
3
Traceroute Architecture
4
Step 1 Turn a hostname into an IP address.
Input dest_name and gethostbyname() this funtion will turn hostname into IP address.
5
Step 2 Create Sockets for connection
UDP uses to send data, it requires datagram socket(SOCK_DGRAM). ICMP packets send back data, it requires raw socket(SOCK_RAW).
6
Step 3 Set TTL TTL begins with 1 and it will plus one in each loop.Use setsockopt() to set the TTL.
7
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.
8
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 “*”.
9
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.
10
Python 2 V.S. Python 3
11
Tracert on Windows
12
Traceroute on CentOS
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.