Remove ping

Ref #12
This commit is contained in:
Ircama 2024-08-30 11:48:57 +02:00
parent 114184913b
commit 2d81571e32

View file

@ -6,18 +6,14 @@ import warnings
from epson_print_conf import EpsonPrinter
# suppress pysnmp warnings
warnings.filterwarnings("ignore", category=SyntaxWarning)
# common printer ports
PRINTER_PORTS = [9100, 515, 631]
class PrinterScanner:
def ping(self, host):
result = subprocess.run(['ping', '-n', '1', host], stdout=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW)
return 'Reply from' in result.stdout.decode('utf-8')
class PrinterScanner:
def check_printer(self, ip, port):
try:
@ -38,7 +34,6 @@ class PrinterScanner:
return None
def scan_ip(self, ip):
if self.ping(ip):
for port in PRINTER_PORTS:
if self.check_printer(ip, port):
try:
@ -48,9 +43,17 @@ class PrinterScanner:
printer_name = self.get_printer_name(ip)
if printer_name:
return {"ip": ip, "hostname": hostname, "name": printer_name}
return {
"ip": ip,
"hostname": hostname,
"name": printer_name
}
else:
return {"ip": ip, "hostname": hostname, "name": "Unknown"}
return {
"ip": ip,
"hostname": hostname,
"name": "Unknown"
}
return None
def get_all_printers(self, ip_addr="", local=False):