项目作者: NicoAdrian

项目描述 :
Async traceroute in python with async dns resolution
高级语言: Python
项目地址: git://github.com/NicoAdrian/aiotraceroute.git
创建时间: 2020-01-24T08:49:20Z
项目社区:https://github.com/NicoAdrian/aiotraceroute

开源协议:MIT License

下载


Simple asynchronous traceroute

Dead simple module which provides asynchronous traceroute with asynchronous dns resolution.

Needs root privileges to be executed (for raw socket)

Installation

pip install aiotraceroute

Example

  1. import asyncio
  2. from aiotraceroute import traceroute
  3. async def main(dest):
  4. # print hop by hop
  5. async for n, addr, host in traceroute(dest):
  6. print(n, addr, host)
  7. # Or run it without iterating
  8. tr = traceroute(dest)
  9. result = await tr.run()
  10. print(result)
  11. asyncio.get_event_loop().run_until_complete(main("google.com"))

API

The traceroute function takes the following arguments:

  • dest: Traceroute destination, can either be a hostname or an IP address.
  • port: Destination port (optionnal, default: 33434)
  • max_hops: Maximum number of hops before reaching final destination (optionnal, default: 30)
  • timeout: Timeout between each hop (optionnal: default: 1s)
  • packet_size: Pakcte size in bytes to send each time (optionnal: default: 60)

The run() method runs the traceroute and returns a list of tuples containing \, \ or None, \ or None

Python versions

Python >= 3.6 are supported

Tests

This project uses unittest.

Run python3.6 tests/test_aiotraceroute.py