A simple command-line tracert implementation in Python 3 using ICMP packets

Overview

Traceroute

A simple command-line tracert implementation in Python 3 using ICMP packets

Screenshot

Details

Traceroute is a networking tool designed for tracing the movement of packets across a network. In this Python 3 implementation, ICMP 'ping' packets are used, much like the Windows tracert.exe program (and unlike Unix tracert which typically uses UDP packets).

The application sends a sequence of ICMP packets to the host, initially with the Time-To-Live field set to 1. As the packet travels across the network to its final destination, each node it passes through will decrement the TTL field by 1. When the field reaches zero the node will respond by saying that the packet could not reach its destination.

+------+           +--------+
|      |  TTL = 1  |        |
|      | --------> |        |
| HOST |           | node 1 |
|      |  timeout  |        |
|      | <-------- |        |
+------+           +--------+

Having now identified the first node that the packet passes through, tracert now sends another ICMP packet with TTL set to 2, which will timeout when it reaches the second node, and so on.

+------+           +--------+           +--------+
|      |  TTL = 2  |        |  TTL = 1  |        |
|      | --------> |        | --------> |        |
| HOST |           | node 1 |           | node 2 |
|      |  timeout  |        |  timeout  |        |
|      | <-------- |        | <-------- |        |
+------+           +--------+           +--------+


+------+           +--------+           +--------+           +--------+
|      |  TTL = 3  |        |  TTL = 2  |        |  TTL = 1  |        |
|      | --------> |        | --------> |        | --------> |        |
| HOST |           | node 1 |           | node 2 |           | node 3 |
|      |  timeout  |        |  timeout  |        |  timeout  |        |
|      | <-------- |        | <-------- |        | <-------- |        |
+------+           +--------+           +--------+           +--------+

Eventually, an ICMP packet will be sent with a sufficiently large TTL value that it can reach the final destination, at which point the process is complete.

+------+           +--------+           +--------+           +--------+           +--------+
|      |  TTL = 4  |        |  TTL = 3  |        |  TTL = 2  |        |  TTL = 1  |        |
|      | --------> |        | --------> |        | --------> |        | --------> |        |
| HOST |           | node 1 |           | node 2 |           | node 3 |           | TARGET |
|      |  success  |        |  success  |        |  success  |        |  success  |        |
|      | <-------- |        | <-------- |        | <-------- |        | <-------- |        |
+------+           +--------+           +--------+           +--------+           +--------+
You might also like...
jrnl is a simple journal application for the command line.
jrnl is a simple journal application for the command line.

jrnl To get help, submit an issue on Github. jrnl is a simple journal application for the command line. You can use it to easily create, search, and v

A simple command line tool for changing the icons of folders or files on MacOS.

Mac OS File Icon Changer Description A small and simple script to quickly change large amounts or a few files and folders icons to easily customize th

A simple command line chat app to communicate via the terminal.

A simple command line chat app to communicate via the terminal. I'm new to networking so sorry if some of my terminology or code is messed up.

Notion-cli-list-manager - A simple command-line tool for managing Notion databases

A simple command-line tool for managing Notion List databases. ✨

🔖 Lemnos: A simple, light-weight command-line to-do list manager.

🔖 Lemnos: CLI To-do List Manager This is a simple program that allows one to manage a to-do list via the command-line. Example $ python3 todo.py add

This is a simple Termo application in command line style
This is a simple Termo application in command line style

my-termo This is a simple Termo application in command line style. This app run a Linux crontab task every day to get a new word. Type termo in your t

Tidier - a simple command line tool that helps you make your files tidy up

Tidier - a simple command line tool that helps you make your files tidy up

A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli.

ABOUT A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Installation pip install -r requirements.txt It use

A Python module and command line utility for working with web archive data using the WACZ format specification

py-wacz The py-wacz repository contains a Python module and command line utility for working with web archive data using the WACZ format specification

Comments
  • All results are

    All results are "timeout". This code can't run successfully.

    1 5011 ms ???.???.???.??? (Timeout) 2 5010 ms ???.???.???.??? (Timeout) 3 5003 ms ???.???.???.??? (Timeout) 4 5003 ms ???.???.???.??? (Timeout) 5 5007 ms ???.???.???.??? (Timeout) 6 5010 ms ???.???.???.??? (Timeout) 7 5013 ms ???.???.???.??? (Timeout) 8 5004 ms ???.???.???.??? (Timeout) 9 5012 ms ???.???.???.??? (Timeout) 10 5012 ms ???.???.???.??? (Timeout) 11 5000 ms ???.???.???.??? (Timeout) 12 5005 ms ???.???.???.??? (Timeout) 13 5006 ms ???.???.???.??? (Timeout) 14 5008 ms ???.???.???.??? (Timeout) 15 5004 ms ???.???.???.??? (Timeout) 16 5010 ms ???.???.???.??? (Timeout) 17 5012 ms ???.???.???.??? (Timeout) 18 5000 ms ???.???.???.??? (Timeout) 19 5007 ms ???.???.???.??? (Timeout) 20 5007 ms ???.???.???.??? (Timeout) 21 5004 ms ???.???.???.??? (Timeout) 22 5012 ms ???.???.???.??? (Timeout) 23 5001 ms ???.???.???.??? (Timeout) 24 5009 ms ???.???.???.??? (Timeout)

    opened by Arjun2848 7
Owner
James
Busily reinventing the wheel
James
A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Stream your favorite shows straight from the command line.

A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Installation pip install -r requirements.txt It use

Jonardon Hazarika 17 Dec 11, 2022
A cd command that learns - easily navigate directories from the command line

NAME autojump - a faster way to navigate your filesystem DESCRIPTION autojump is a faster way to navigate your filesystem. It works by maintaining a d

William Ting 14.5k Jan 3, 2023
AML Command Transfer. A lightweight tool to transfer any command line to Azure Machine Learning Services

AML Command Transfer (ACT) ACT is a lightweight tool to transfer any command from the local machine to AML or ITP, both of which are Azure Machine Lea

Microsoft 11 Aug 10, 2022
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

null 37 Dec 15, 2022
A very simple and lightweight ToDo app using python that can be used from the command line

A very simple and lightweight ToDo app using python that can be used from the command line

Nilesh Sengupta 2 Jul 20, 2022
Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Phil Wang 4.4k Jan 9, 2023
Simple command-line implementation of minesweeper

minesweeper This is a Python implementation of 2-D Minesweeper! Check out the tutorial here: https://youtu.be/Fjw7Lc9zlyU You start a game by running

Kylie 49 Dec 10, 2022
Zecwallet-Python is a simple wrapper around the Zecwallet Command Line LightClient written in Python

A wrapper around Zecwallet Command Line LightClient, written in Python Table of Contents About Installation Usage Examples About Zecw

Priveasy 2 Sep 6, 2022
A simple command line dumper written in Python 3.

A simple command line dumper written in Python 3.

ImFatF1sh 1 Oct 10, 2021
A simple command line tool written in python to manage a to-do list

A simple command line tool written in python to manage a to-do list Dependencies: python Commands: todolist (-a | --add) [(-p | --priority)] [(-l | --

edwloef 0 Nov 2, 2021