Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, target: Tuple[str, int], packet_count: int,
timeout: int=3) -> None:
self._target = target
self._packet_count = packet_count
self._timeout = timeout
self.packets_received = 0
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def __init__(self, bind_port: int) -> None:
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._sock.bind(('0.0.0.0', bind_port))
async def sendto_from(bind_addr, data, addr):
try:
if bind_addr not in socks:
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
sender.bind(bind_addr)
socks[bind_addr] = sender
sender = socks[bind_addr]
async with sender:
await sender.sendto(data, addr)
except OSError as e:
if verbose > 0:
print(e, bind_addr)
def __init__(self, ns=None):
self.ns = ns
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if "source_addr" in self.ns:
self.sock.bind(self.ns["source_addr"])
self._task = None
def bind(self):
self.sock = socket.socket(self.family, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
self.sock.bind(self.address)
self.sock.listen(5)
self.address = self.sock.getsockname()
async def sendto_from(bind_addr, data, addr):
try:
if bind_addr not in socks:
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
sender.bind(bind_addr)
socks[bind_addr] = sender
sender = socks[bind_addr]
async with sender:
await sender.sendto(data, addr)
except OSError as e:
if verbose > 0:
print(e, bind_addr)
def __init__(self, bind_port: int) -> None:
self._bind_port = bind_port
self._sock = socket.socket()
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self._sock.bind(('0.0.0.0', bind_port))
async def sendto_from(bind_addr, data, addr):
try:
if bind_addr not in socks:
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
sender.bind(bind_addr)
socks[bind_addr] = sender
sender = socks[bind_addr]
async with sender:
await sender.sendto(data, addr)
except OSError as e:
if verbose > 0:
print(e, bind_addr)
return sendto_from
async def sendto_from(bind_addr, data, addr):
try:
if bind_addr not in socks:
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
sender.bind(bind_addr)
socks[bind_addr] = sender
sender = socks[bind_addr]
async with sender:
await sender.sendto(data, addr)
except OSError as e:
gvars.logger.debug(f"{bind_addr} {e}")