Skip to content

Commit

Permalink
@mbridak Had an Oops, better not mention it.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Nov 12, 2024
1 parent 752b11a commit 9584558
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion not1mm/lib/cat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, interface: str, host: str, port: int) -> None:

def __check_sane_ip(self, ip: str) -> bool:
"""check if IP address look normal"""
x = ip.split()
x = ip.split(".")
if len(x) != 4:
return False
for y in x:
Expand Down
31 changes: 28 additions & 3 deletions not1mm/lib/cwinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def __init__(self, servertype: int, host: str, port: int) -> None:
self.speed = 20
self.winkeyer_functions = []
if self.servertype == 2:
if not self.__check_sane_ip(self.host):
logger.critical(f"Bad IP: {self.host}")
return
with ServerProxy(f"http://{self.host}:{self.port}") as proxy:
try:
self.winkeyer_functions = proxy.system.listMethods()
Expand All @@ -47,6 +50,16 @@ def __init__(self, servertype: int, host: str, port: int) -> None:
"http://%s:%s, xmlrpc Connection Refused", self.host, self.port
)

def __check_sane_ip(self, ip: str) -> bool:
"""check if IP address look normal"""
x = ip.split(".")
if len(x) != 4:
return False
for y in x:
if not y.isnumeric():
return False
return True

def sendcw(self, texttosend):
"""sends cw to k1el"""
logger.debug(f"{texttosend=} {self.servertype=}")
Expand All @@ -61,7 +74,7 @@ def sendcw(self, texttosend):
def _sendcw_xmlrpc(self, texttosend):
"""sends cw to xmlrpc"""
logger.debug("xmlrpc: %s", texttosend)
if texttosend:
if texttosend and self.__check_sane_ip(self.host):
with ServerProxy(f"http://{self.host}:{self.port}") as proxy:
try:
proxy.k1elsendstring(texttosend)
Expand All @@ -76,23 +89,35 @@ def _sendcw_xmlrpc(self, texttosend):
logger.debug(
"http://%s:%s, xmlrpc Connection Refused", self.host, self.port
)
else:
logger.critical(f"Bad IP: {self.host}")

def _sendcw_udp(self, texttosend):
"""send cw to udp port"""
logger.debug("UDP: %s", texttosend)
if texttosend:
if texttosend and self.__check_sane_ip(self.host):
server_address_port = (self.host, self.port)
# bufferSize = 1024
udp_client_socket = socket.socket(
family=socket.AF_INET, type=socket.SOCK_DGRAM
)
udp_client_socket.sendto(bytes(texttosend, "utf-8"), server_address_port)
try:
udp_client_socket.sendto(
bytes(texttosend, "utf-8"), server_address_port
)
except socket.gaierror:
...
else:
logger.critical(f"Bad IP: {self.host.encode()}")

def _sendcwcat(self, texttosend):
"""..."""

def set_winkeyer_speed(self, speed):
"""doc"""
if not self.__check_sane_ip(self.host):
logger.critical(f"Bad IP: {self.host}")
return
with ServerProxy(f"http://{self.host}:{self.port}") as proxy:
try:
if "setspeed" in self.winkeyer_functions:
Expand Down

0 comments on commit 9584558

Please sign in to comment.