当前位置: 首页>>代码示例>>Python>>正文


Python Node.add_mac方法代码示例

本文整理汇总了Python中node.Node.add_mac方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_mac方法的具体用法?Python Node.add_mac怎么用?Python Node.add_mac使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在node.Node的用法示例。


在下文中一共展示了Node.add_mac方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_aliases

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def import_aliases(self, aliases):
    for mac, alias in aliases.items():
      try:
        node = self.maybe_node_by_mac([mac])
      except:
        try:
          node = self.maybe_node_by_fuzzy_mac(mac)
        except:
          # create an offline node
          node = Node()
          node.add_mac(mac)
          self._nodes.append(node)

      if 'name' in alias:
        node.name = alias['name']

      if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
        node.interfaces[mac].vpn = True

      if 'gps' in alias:
        node.gps = alias['gps']

      if 'firmware' in alias:
        node.firmware = alias['firmware']

      if 'id' in alias:
        node.id = alias['id']
开发者ID:smoe,项目名称:ffmap-backend,代码行数:29,代码来源:nodedb.py

示例2: import_aliases

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def import_aliases(self, aliases):
    for mac, alias in aliases.items():
      try:
        node = self.maybe_node_by_mac([mac])
      except:
        try:
          node = self.maybe_node_by_fuzzy_mac(mac)
        except:
          # create an offline node
          node = Node()
          node.add_mac(mac)
          self._nodes.append(node)

      if 'name' in alias:
        node.name = alias['name']

      if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
        try:
          node.interfaces[mac].vpn = True
        except:
          print("error with ", mac)

      if 'gps' in alias:
        node.gps = alias['gps']

      if 'firmware' in alias:
        node.firmware = alias['firmware']

      if 'model' in alias:
        node.model = alias['model']

      if 'uptime' in alias:
        node.uptime = alias['uptime']
      
      if 'id' in alias:
        node.id = alias['id']
     
      if 'addresses' in alias:
        node.addresses = alias['addresses']
 
      if 'autoupdater_enabled' in alias: 
        node.autoupdater['enabled'] = alias['autoupdater_enabled']
      
      if 'autoupdater_branch' in alias: 
       node.autoupdater['branch'] = alias['autoupdater_branch']

      if 'contact' in alias:
       node.contact = alias['contact']
开发者ID:freifunkMUC,项目名称:ffmap-backend,代码行数:50,代码来源:nodedb.py

示例3: import_aliases

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def import_aliases(self, aliases):
    for mac, alias in aliases.items():
      try:
        node = self.maybe_node_by_mac([mac])
      except:
        try:
          node = self.maybe_node_by_fuzzy_mac(mac)
        except:
          # create an offline node
          node = Node()
          node.add_mac(mac)
          self._nodes.append(node)

      if 'name' in alias:
        node.name = alias['name']

      if 'vpn' in alias and alias['vpn'] and mac and node.interfaces and mac in node.interfaces:
        node.interfaces[mac].vpn = True

      if 'gps' in alias:
        node.gps = alias['gps']

      if 'firmware' in alias:
        node.firmware = alias['firmware']

      if 'id' in alias:
        node.id = alias['id']

      if 'uptime' in alias:
        node.uptime = alias['uptime']

      if 'tx_bytes' in alias:
        node.tx_bytes = alias['tx_bytes']

      if 'rx_bytes' in alias:
        node.rx_bytes = alias['rx_bytes']

      if 'loadavg' in alias:
        node.loadavg = alias['loadavg']

      if 'autoupdater' in alias:
        node.autoupdater = alias['autoupdater']

      if 'branch' in alias:
        node.branch = alias['branch']

      if 'hardware' in alias:
        node.hardware = alias['hardware']
开发者ID:lcb01a,项目名称:ffmap-backend,代码行数:50,代码来源:nodedb.py

示例4: parse_vis_data

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def parse_vis_data(self,vis_data):
    for x in vis_data:

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except:
          node = Node()
          node.flags['online'] = True
          if 'legacy' in x:
            node.flags['legacy'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for x in vis_data:

      if 'router' in x:
        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if 'legacy' in x:
            node.flags['legacy'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        # If it's a TT link and the MAC is very similar
        # consider this MAC as one of the routers
        # MACs
        if 'gateway' in x and x['label'] == "TT":
          if is_similar(x['router'], x['gateway']):
            node.add_mac(x['gateway'])

            # skip processing as regular link
            continue

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor']))
            except:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if x['label'] == 'TT':
            node.flags['client'] = True

          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for x in vis_data:

      if 'router' in x:
        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

        if x['label'] == "TT":
          link.type = "client"

        self._links.append(link)

    for x in vis_data:

      if 'primary' in x:
        try:
          node = self.maybe_node_by_mac((x['primary'], ))
        except:
          continue

        node.id = x['primary']
开发者ID:smoe,项目名称:ffmap-backend,代码行数:101,代码来源:nodedb.py

示例5: parse_vis_data

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def parse_vis_data(self,vis_data):
    for x in vis_data:

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for x in vis_data:
      if 'router' in x:
        # TTs will be processed later
        if x['label'] == "TT":
          continue

        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor'], ))
            except KeyError:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except KeyError:
          node = Node()
          node.lastseen = self.time
          node.firstseen = self.time
          node.flags['online'] = True
          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for x in vis_data:
      if 'router' in x:
        # TTs will be processed later
        if x['label'] == "TT":
          continue

        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except KeyError:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

        self._links.append(link)

    for x in vis_data:
      if 'primary' in x:
        try:
          node = self.maybe_node_by_mac((x['primary'], ))
        except KeyError:
          continue

        node.id = x['primary']

    for x in vis_data:
      if 'router' in x and x['label'] == 'TT':
        try:
          node = self.maybe_node_by_mac((x['router'], ))
          node.add_mac(x['gateway'])
          node.clientcount += 1
        except KeyError:
          pass
 
#.........这里部分代码省略.........
开发者ID:FreiFunkMuenster,项目名称:ffmap-backend,代码行数:103,代码来源:nodedb.py

示例6: import_batman

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def import_batman(self, lines):

    for line in lines:
      x = json.loads(line)

      if 'of' in x:
        try:
          node = self.maybe_node_by_mac((x['of'], x['secondary']))
        except:
          node = Node()
          node.flags['online'] = True
          self._nodes.append(node)

        node.add_mac(x['of'])
        node.add_mac(x['secondary'])

    for line in lines:
      x = json.loads(line)

      if 'router' in x:
        try:
          node = self.maybe_node_by_mac((x['router'], ))
        except:
          node = Node()
          node.flags['online'] = True
          node.add_mac(x['router'])
          self._nodes.append(node)

        # If it's a TT link and the MAC is very similar
        # consider this MAC as one of the routers
        # MACs
        if 'gateway' in x and x['label'] == "TT":
          router = list(int(i, 16) for i in x['router'].split(":"))
          gateway = list(int(i, 16) for i in x['gateway'].split(":"))

          # first byte must only differ in bit 2
          if router[0] == gateway[0] | 2:
            # count different bytes
            a = [x for x in zip(router[1:], gateway[1:]) if x[0] != x[1]]

            # no more than two additional bytes must differ
            if len(a) <= 2:
              delta = 0
              if len(a) > 0:
                delta = sum(abs(i[0] -i[1]) for i in a)

              if delta < 8:
                # This TT link looks like a mac of the router!
                node.add_mac(x['gateway'])

                # skip processing as regular link
                continue

        try:
          if 'neighbor' in x:
            try:
              node = self.maybe_node_by_mac((x['neighbor']))
            except:
              continue

          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          node = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          node = Node()
          node.flags['online'] = True
          if x['label'] == 'TT':
            node.flags['client'] = True

          node.add_mac(x['neighbor'])
          self._nodes.append(node)

    for line in lines:
      x = json.loads(line)

      if 'router' in x:
        try:
          if 'gateway' in x:
            x['neighbor'] = x['gateway']

          router = self.maybe_node_by_mac((x['router'], ))
          neighbor = self.maybe_node_by_mac((x['neighbor'], ))
        except:
          continue

        # filter TT links merged in previous step
        if router == neighbor:
          continue

        link = Link()
        link.source = LinkConnector()
        link.source.interface = x['router']
        link.source.id = self._nodes.index(router)
        link.target = LinkConnector()
        link.target.interface = x['neighbor']
        link.target.id = self._nodes.index(neighbor)
        link.quality = x['label']
        link.id = "-".join(sorted((link.source.interface, link.target.interface)))

#.........这里部分代码省略.........
开发者ID:NeoRaider,项目名称:ffmap-d3,代码行数:103,代码来源:nodedb.py

示例7: import_wikigps

# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import add_mac [as 别名]
  def import_wikigps(self, url):
    def fetch_wikitable(url):
      f = urlopen(url)

      soup = BeautifulSoup(f)

      table = soup.find_all("table")[0]

      rows = table.find_all("tr")

      headers = []

      data = []

      def maybe_strip(x):
        if isinstance(x.string, str):
          return x.string.strip()
        else:
          return ""

      for row in rows:
        tds = list([maybe_strip(x) for x in row.find_all("td")])
        ths = list([maybe_strip(x) for x in row.find_all("th")])

        if any(tds):
          data.append(tds)

        if any(ths):
          headers = ths

      nodes = []

      for d in data:
        nodes.append(dict(zip(headers, d)))

      return nodes

    nodes = fetch_wikitable(url)

    for node in nodes:
      try:
        node['MAC'] = node['MAC'].split(',')
      except KeyError:
        pass

      try:
        node['GPS'] = node['GPS'].split(',')
      except KeyError:
        pass

      try:
        node['Nick'] = node['Nick'].split(',')
      except KeyError:
        pass

      nodes = zip_longest(node['MAC'], node['GPS'], node['Nick'])

      for data in nodes:
        if not data[0]:
          continue

        try:
          node = self.maybe_node_by_mac((data[0], ))
        except:
          node = Node()
          node.add_mac(data[0])
          self._nodes.append(node)

        if data[1]:
          node.gps = data[1]

        if data[2]:
          node.name = data[2]
开发者ID:NeoRaider,项目名称:ffmap-d3,代码行数:75,代码来源:nodedb.py


注:本文中的node.Node.add_mac方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。