41 lines
943 B
Python
41 lines
943 B
Python
from datetime import datetime
|
|
from time import sleep
|
|
import ctypes
|
|
import socket
|
|
|
|
LIBC = ctypes.CDLL('libc.so.6')
|
|
|
|
|
|
def usleep(us):
|
|
LIBC.usleep(us)
|
|
|
|
|
|
def wait_until_time_unit(unit):
|
|
t = datetime.utcnow()
|
|
t.timestamp()
|
|
sleep(unit - t.timestamp() % unit)
|
|
|
|
|
|
class ICMPv6Socket:
|
|
ICMPV6_DATA = b'\x80\0\0\0\0\0\0\0'
|
|
|
|
def __init__(self, ipv6_src):
|
|
self.ipv6_src = ipv6_src
|
|
self.create_socket()
|
|
|
|
def create_socket(self):
|
|
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW,
|
|
socket.getprotobyname('ipv6-icmp'))
|
|
self.sock.bind((self.ipv6_src, 0))
|
|
|
|
def ping(self, target):
|
|
try:
|
|
self.sock.sendto(self.ICMPV6_DATA, (target, 0, 0, 0))
|
|
except:
|
|
self.create_socket()
|
|
|
|
def ping_batch(self, targets, interval_us = 10):
|
|
for target in targets:
|
|
self.ping(target)
|
|
usleep(interval_us)
|