Esempio n. 1
0
def test_get_interface_linux(monkeypatch):
  '''Check that when platform.system() returns Linux, get_interface() should call linux_iface()'''
  def mockreturn():
    return 'Linux'
  monkeypatch.setattr('utils.platform.system', mockreturn)
  x = get_interface()
  assert x == linux_iface()
Esempio n. 2
0
def test_get_interface_darwin(monkeypatch):
  '''Check that when platform.system() returns Darwin, get_interface() should call darwin_iface()'''
  def mockreturn():
    return 'Darwin'
  monkeypatch.setattr('utils.platform.system', mockreturn)
  x = get_interface()
  assert x == darwin_iface()
Esempio n. 3
0
 def send(self):
     packet = self.get_packet()
     if packet:
         #logger.debug('send6 %s', packet)
         ttl = struct.pack('@i', self._TTL)
         address = self._BROADCAST + get_interface()
         addrs = socket.getaddrinfo(address, self._PORT, socket.AF_INET6, socket.SOCK_DGRAM)
         addr = addrs[0]
         (family, socktype, proto, canonname, sockaddr) = addr
         s = socket.socket(family, socktype, proto)
         s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, ttl)
         try:
             s.sendto(packet + b'\0', sockaddr)
         except:
             logger.debug('LocalNodes6.send failed', exc_info=1)
         s.close()
Esempio n. 4
0
async def main_handler(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)
    async for msg in ws:
        if msg.type == aiohttp.WSMsgType.TEXT:
            json_msg = aiohttp.WSMessage.json(msg)
            if json_msg['fname'] == 'closeSocket':
                print('Closing socket')
                await ws.close()
            elif json_msg['fname'] == 'getNetworkInfo':
                print('Getting network info')
                json_iface = json.dumps(get_interface())
                await ws.send_str(json_iface)
            elif json_msg['fname'] == 'arpScan':
                json_arp_table = json.dumps(
                    get_arp_table(json_msg['args']['ifaddr']))
                await ws.send_str(json_arp_table)
        elif msg.type == aiohttp.WSMsgType.ERROR:
            print('ws connection closed with exception %s' % ws.exception())
    print('websocket connection closed')
    return ws
Esempio n. 5
0
 def test_get_interface_platform_calls(self, mocked_platform):
   '''Check that get_interface() calls platform.system() 3 times'''
   get_interface()
   assert mocked_platform.system.call_count == 3
Esempio n. 6
0
    def fix_config(self):
        # Add default frec
        if "def_frec" not in self.conf["node"]:
            self.conf["node"]["def_frec"] = 0.05

        # Add ethernet network
        if "ethernet" not in self.conf["node"]:
            self.conf["node"]["ethernet"] = utils.get_interface()

        # Add IP address
        if "ip" not in self.conf["node"]:
            self.conf["node"]["ip"] = utils.get_ip_address(
                self.conf["node"]["ethernet"])

        # Add default name
        if "name" not in self.conf["node"]:
            self.conf["node"]["name"] = "default_name"

        # Add port_ns
        if "port_ns" not in self.conf["node"]:
            self.conf["node"]["port_ns"] = 9090

        # Add port_node
        if "port_node" not in self.conf["node"]:
            self.conf["node"]["port_node"] = 4040

        # Add start_port
        if "start_port" not in self.conf["node"]:
            self.conf["node"]["start_port"] = 5050

        # Add def_worker
        if "def_worker" not in self.conf["node"]:
            self.conf["node"]["def_worker"] = True

        # Add password
        if "password" not in self.conf["node"]:
            self.conf["node"]["password"] = self.conf["node"]["name"]

        # Add bigbrother password
        if "bigbrother-password" not in self.conf["node"]:
            self.conf["node"]["bigbrother-password"] = "******"

        # Services and components config
        for k, v in self.components.items() + self.services.items():
            if "worker_run" not in v:
                v["worker_run"] = True
            if "mode" not in v:
                v["mode"] = "public"
            if "frec" not in v:
                v["frec"] = self.conf["node"]["def_frec"]
            v["docstring"] = {}
            v["exposed"] = {}
        for k, v in self.services.items():
            v["mode"] = "local"

        # Services configuration
        newservices = {}
        for n in self.services:
            if _clases.get(self.services[n]["cls"], None) is not None:
                if len(_clases[self.services[n]["cls"]]) > 1:
                    print("Warning: there are many modules {} for class {}".
                          format(_clases[self.services[n]["cls"]],
                                 self.services[n]["cls"]))
                self.services[n]["module"] = _clases[self.services[n]
                                                     ["cls"]][0]
                if "." not in n:
                    newservices[self.node["name"] + "." + n] = self.services[n]
                else:
                    newservices[n] = self.services[n]
            else:
                print(
                    colored(
                        "ERROR: Class {} not found or error in Modules".format(
                            self.services[n]["cls"]), "red"))
                for k_error, error in _modules_errors.iteritems():
                    print("Module {}: {}".format(k_error, error))
                exit()
            if ("-->") in self.services[n]:
                sp = [
                    self.node["name"] + "." + x
                    for x in self.services[n]["-->"] if x.find(".") < 0
                ]
                cp = [x for x in self.services[n]["-->"] if x.find(".") >= 0]
                self.services[n]["-->"] = sp + cp  # esto se puede simplificar

        self.services = newservices

        for n in self.services:
            self.services[n]["_locals"] = []
            self.services[n]["_resolved_remote_deps"] = []
            if "-->" in self.services[n]:
                self.services[n]["_locals"], self.services[n][
                    "_resolved_remote_deps"] = self.local_remote(
                        self.services, n)
        newrobot = {}
        # Components configuration
        for n in self.components:
            if _clases.get(self.components[n]["cls"], None) is not None:
                if len(_clases[self.components[n]["cls"]]) > 1:
                    print("Warning: there are many modules {} for class {}".
                          format(_clases[self.components[n]["cls"]],
                                 self.components[n]["cls"]))
                self.components[n]["module"] = _clases[self.components[n]
                                                       ["cls"]][0]
            else:
                print(
                    colored(
                        "ERROR: Class {} not found or error in Modules".format(
                            self.components[n]["cls"]), "red"))
                for k_error, error in _modules_errors.iteritems():
                    print("Module {}: {}".format(k_error, error))
                exit()
            self.components[n]["_services"] = list(self.services)
            if ("-->") in self.components[n]:
                sp = [
                    self.node["name"] + "." + x
                    for x in self.components[n]["-->"] if x.find(".") < 0
                ]
                cp = [x for x in self.components[n]["-->"] if x.find(".") >= 0]
                self.components[n][
                    "-->"] = sp + cp  # esto se puede simplificar
            if n.find(".") == -1:
                newrobot[self.node["name"] + "." + n] = self.components[n]
            else:
                newrobot[n] = self.components[n]

        self.components = newrobot

        for n in self.components:
            self.components[n]["_locals"] = []
            self.components[n]["_unr_remote_deps"] = []
            self.components[n]["_resolved_remote_deps"] = []
            if "-->" in self.components[n]:
                self.components[n]["_locals"], self.components[n][
                    "_resolved_remote_deps"] = self.local_remote(
                        self.components, n)