-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ping-isp utility to auto-detect the ISP first hop.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import itertools | ||
import socket | ||
import importlib | ||
import functools | ||
|
||
import autocommand | ||
import icmplib | ||
|
||
|
||
def is_router(addr): | ||
return addr.startswith('192.168') or 'amplifi' in socket.gethostbyaddr(addr) | ||
|
||
|
||
def _patch_traceroute_privilege(): | ||
""" | ||
Force the socket objects to disable privilege. | ||
""" | ||
module = importlib.import_module('icmplib.traceroute') | ||
module.ICMPv4Socket = functools.partial(module.ICMPv4Socket, privileged=False) | ||
module.ICMPv6Socket = functools.partial(module.ICMPv6Socket, privileged=False) | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
def main(): | ||
""" | ||
Detect the ISP and ping it for some stats. | ||
""" | ||
_patch_traceroute_privilege() | ||
trace = icmplib.traceroute('1.1.1.1', max_hops=3, fast=True) | ||
addresses = (hop.address for hop in trace) | ||
ISP = next(itertools.filterfalse(is_router, addresses)) | ||
print('pinging', ISP, f'({socket.gethostbyaddr(ISP)[0]})') | ||
host = icmplib.ping(ISP, count=30, privileged=False) | ||
print(host) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added ping-isp utility to auto-detect the ISP first hop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters