Skip to content

mvenditto/TcpTraceRoute.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TcpTraceRoute

A TCP-based traceroute library and tool inspired by the original tcptraceroute.

Built with packetnet and sharppcap.

Note behavior may vary from the original tool, and some options are not supported yet (e.g trackport)

Cli

Help
Description:

Usage:
  tcptraceroute-net <dst-host> [<dst-port>] [options]

Arguments:
  <dst-host>
  <dst-port>  [default: 80]

Options:
  -d                               debug mode [default: False]
  -n                               do not resolve probe hostname [default: True]
  -q, --num-queries <num-queries>  [default: 3]
  -f, --first-ttl <first-ttl>      [default: 1]
  --track-port                     [default: False]
  -P, --force-port                 [default: False]
  --dnat                           [default: False]
  -i, --interface <interface>
  -l, --packet-len <packet-len>    [default: 0]
  -m, --max-ttl <max-ttl>          [default: 30]
  -t, --tos <tos>                  [default: 0]
  -s, --src-address <src-address>
  -p, --src-port <src-port>        [default: 0]
  -w, --wait-time <wait-time>      packet read timeout (ms) [default: 3000]
  -S                               set SYN tcp flag [default: True]
  -A                               set ACK tcp flag [default: False]
  -E                               set ECN tcp flag [default: False]
  -U                               set URG tcp flag [default: False]
  --version                        Show version information
  -?, -h, --help                   Show help and usage information

Cli - Samples

traceroute-net github.com -q 1
 Selected device Wi-Fi (Intel(R) Wi-Fi 6 AX201 160MHz), address 192.168.1.56, port 60563 for outgoing packets
 Tracing the path to github.com (140.82.121.4) on TCP port 80, 30 hops max
 1  home-life.hub      1.411 ms
 2  151.6.142.56       7.518 ms
 3  151.6.57.36        7.175 ms
 4  151.6.6.68         9.696 ms
 5  151.6.7.181        10.650 ms
 6  *                  *
 7  64.125.30.254      26.075 ms
 8  ae1.mcs1.fra9.de.eth.zayo.com    32.603 ms
 9  82.98.193.29.IPYX-270403-002-ZYO.zip.zayo.com    26.751 ms
10  *                  *
11  *                  *
12  lb-140-82-121-4-fra.github.com  [open]  26.199 ms
traceroute-net github.com -q 3 -n
 Selected device Wi-Fi (Intel(R) Wi-Fi 6 AX201 160MHz), address 192.168.1.56, port 60563 for outgoing packets
 Tracing the path to github.com (140.82.121.3) on TCP port 80, 30 hops max
 1  192.168.1.1        1.873 ms  1.196 ms  1.230 ms
 2  151.6.142.56       6.731 ms  7.207 ms  6.189 ms
 3  151.6.57.36        6.432 ms  6.351 ms  9.545 ms
 4  151.6.6.68         9.502 ms  9.882 ms  9.262 ms
 5  151.6.7.181        10.197 ms  11.756 ms  10.146 ms
 6  80.81.194.26       25.581 ms  25.906 ms  25.646 ms
 7  64.125.30.254      26.460 ms  25.677 ms  25.404 ms
 8  64.125.29.65       31.942 ms  32.211 ms  31.858 ms
 9  82.98.193.29       25.576 ms  25.550 ms  26.520 ms
10  *                  *  *  *
11  *                  *  *  *
12  140.82.121.3     [open]  25.800 ms  25.744 ms  835.491 ms
traceroute-net github.com -q 1 -n --dot
 Selected device Wi-Fi (Intel(R) Wi-Fi 6 AX201 160MHz), address 192.168.1.56, port 60563 for outgoing packets
 Tracing the path to github.com (140.82.121.3) on TCP port 80, 30 hops max
 1  192.168.1.1        1.873 ms  1.196 ms  1.230 ms
 [...TRUNCATED FOR BREVITY...]
 
 digraph {
  {
    host
    1[label="192.168.1.1" ]
    2[label="151.6.142.56" ]
    3[label="151.6.57.40" ]
    4[label="151.6.0.190" ]
    5[label="151.6.7.239" ]
    6[label="80.81.194.26" ]
    7[label="64.125.30.254" ]
    8[label="64.125.29.65" ]
    9[label="82.98.193.29" ]
    10[label="*" color=red]
    11[label="*" color=red]
    12[label="140.82.121.4" ]
  }
  host->1 [label="  2.228 ms"]
  host->2 [label="  8.137 ms" style=dotted]
  1->2 [label="  10.364 ms"]
  host->3 [label="  6.886 ms" style=dotted]
  2->3 [label="  17.250 ms"]
  host->4 [label="  26.925 ms" style=dotted]
  3->4 [label="  44.175 ms"]
  host->5 [label="  22.965 ms" style=dotted]
  4->5 [label="  67.140 ms"]
  host->6 [label="  23.855 ms" style=dotted]
  5->6 [label="  90.995 ms"]
  host->7 [label="  24.454 ms" style=dotted]
  6->7 [label="  115.449 ms"]
  host->8 [label="  62.802 ms" style=dotted]
  7->8 [label="  178.252 ms"]
  host->9 [label="  19.341 ms" style=dotted]
  8->9 [label="  197.593 ms"]
  host->10 [label="  -1.000 ms" style=dotted]
  9->10 [label="  197.593 ms"]
  host->11 [label="  -1.000 ms" style=dotted]
  10->11 [label="  197.593 ms"]
  host->12 [label="  19.376 ms" style=dotted]
  11->12 [label="  216.969 ms"]
}
See rendered at:
https://dreampuf.github.io/GraphvizOnline/#digraph%20%7B%0D%0A%20%20%7B%[...TRUNCATED...]

See render at dreampuf.github.io/GraphvizOnline

Addition features

Route graph generation with --dot

tcptraceroute-net github.com -q 1 --dot

See the Cli - Samples section for more details.

Code

var dstAddress = IPAddress.Parse("8.8.8.8");

var srcAddress = await NetworkHelpers.FindSourceAddress(dstAddress);

var (device, networkInterface) = NetworkHelpers.FindDevice(sourceAddress);

var options = new TcpTraceRouteOptions
{
    TcpDestinationPort = 80,
    NumQueries = 3,
    MaxTtl = 30,
    Timeout = TimeSpan.FromMilliseconds(3000),
    SourceAddress = srcAddress,
    DestinationAddress = dstAddress,
};

using var traceroute = new TcpTraceRouteCapture(device, networkInterface, options);
    
traceroute.ProbeCompleted += (_, e) => 
{
    var p = e.Probe;
    Console.WriteLine($"ttl={p.Ttl} q={p.QueryNum} src={p.Address} delta={p.Delta}ms");
};

var result = traceroute.Run();

var destinationReached = result.Probes
    .TakeLast(opts.NumQueries)
    .Any(p => p.Address.Equals(opts.DestinationAddress));

if (!destinationReached)
{
    Console.WriteLine("Destination not reached");
}

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages