Commit 4ddcb4f6 authored by Mateus Goto's avatar Mateus Goto

[UPDATED] IPfinder and new classes

parent 00d76691
class controlInterface:
\ No newline at end of file
from abc import abstractmethod
import socket
from Utility.RefineOutput import RefineOutput
from Utility.IPFinder import IPFinder
......@@ -12,14 +13,9 @@ class NHR9400:
self.__out = RefineOutput
def setIp(self):
self.__ip = "1912c25"
def getIp(self):
clients = IPFinder.getAllIp()
for client in clients:
self.__s.connect((client['ip'], 5025))
self.__s.send("SYST:RWL\n")
self.__s.send("*IDN?\n")
@abstractmethod
def locateIp(self):
pass
#Function that receives messages back and transform it in a string
......
from NHR9400series.NHR9400 import NHR9400
from Utility import IPFinder
class NHR9410(NHR9400):
def __init__(self):
super().__init__("NHR9410")
def getIp(self):
return super().getIp()
def locateIp(self, clients = []):
for client in clients:
self.__s.connect((client, 5025))
self.__s.send("SYST:RWL\n") #Command to activate remote control and locking the touchscreen
self.__s.send("*IDN?\n")
recv = self.receiveString()
if str.find("NH Research,9410-") != -1: #if find this subtring
self.__ip = client
clients.remove(client)
break
else:
self.__s.close()
from NHR9400series.NHR9400 import NHR9400
from Utility.RefineOutput import RefineOutput
class NHR9430(NHR9400):
def __init__(self):
super().__init__("NHR9410")
def locateIp(self,clients = []):
for client in clients:
self.__s.connect((client, 5025))
self.__s.send("SYST:RWL\n") #Command to activate remote control and locking the touchscreen
self.__s.send("*IDN?\n")
recv = super().receiveString()
if recv.find("NH Research,9410-") != -1: #if find this subtring
self.__ip = client
clients.remove(client)
break
else:
self.__s.close()
......@@ -5,8 +5,12 @@ from scapy.all import ARP, Ether, srp
class IPFinder:
def __init__(self):
self.__clients = self.getAllIp()
#uses socket and scapy to scan the entire local network and returns all the IPs adresses of the devices connects in this networok
def getAllIp():
def __getAllIp(self):
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(("10.255.255.255",1))
local_ip = s.getsockname()[0]
......@@ -20,4 +24,10 @@ class IPFinder:
clients = []
for sent, received in result:
clients.append({"ip": received.psrc})
return clients
self.__clients = clients
def deteleIp(self, ip):
self.__clients.remove(ip)
def getList(self):
return self.__clients
\ No newline at end of file
......@@ -7,4 +7,4 @@ class RefineOutput:
def byteToString(recv):
recv = recv.decode("UTF-8")
return recv
\ No newline at end of file
return str(recv)
\ No newline at end of file
from Control_Interface.controlInterface import controlInterface
controlInterface()
\ No newline at end of file
#Arquivo para teste em geral
import socket
from scapy.all import ARP, Ether, srp, arping
import time
start = time.time()
def getAllIp():
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(("10.255.255.255",1))
local_ip = s.getsockname()[0]
print(local_ip)
local_ip = local_ip[:-1] + "/24"
print(local_ip)
print(type(local_ip))
arp = ARP(pdst=local_ip)
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp
result= srp(packet, timeout=3,retry = 1, verbose = 0)[0]
clients = []
for sent, received in result:
clients.append(received.psrc)
for client in clients:
print(client)
getAllIp()
print (time.time() - start)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment