コード例 #1
0
ファイル: networks.py プロジェクト: nlindblad/ipplan2sqlite
def add_all_rfc_1918(c):
    for ipv4 in ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']:
        vlan = None
        name = "RFC_" + ipv4.split('.')[0]
        short_name = name
        terminator = None
        net_ipv4 = ipcalc.Network(ipv4)
        ipv4_gateway = net_ipv4[1]
        ipv4_netmask = str(net_ipv4.netmask())
        ipv4_netmask_dec = int(str(ipv4).split("/")[1])
        node_id = node(c)

        row = [
            node_id, name, short_name, vlan, terminator,
            ip2long(ipv4, Address.IPv4),
            str(ipv4), None,
            ip2long(ipv4_netmask, Address.IPv4),
            str(ipv4_netmask), None,
            ip2long(ipv4_gateway, Address.IPv4),
            str(ipv4_gateway), None,
            int(ipv4_netmask_dec), 0
        ]

        c.execute(
            'INSERT INTO network VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
            row)
コード例 #2
0
ファイル: TestParser.py プロジェクト: nlindblad/ipplan2sqlite
 def testParseIPv4(self):
     self.assertEquals(
         processor.ip2long('8.8.8.8', Address.IPv4),
         134744072
     )
     self.assertEquals(
         processor.ip2long('77.80.251.247/32', Address.IPv4),
         1297153015
     )
コード例 #3
0
ファイル: networks.py プロジェクト: dhtech/ipplan2sqlite
def add_all_rfc_1918(c):
    for ipv4 in ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']:
        vlan = None
        name = "RFC_" + ipv4.split('.')[0]
        short_name = name
        terminator = None
        net_ipv4 = ipcalc.Network(ipv4)
        ipv4_gateway = net_ipv4[1]
        ipv4_netmask = str(net_ipv4.netmask())
        ipv4_netmask_dec = int(str(ipv4).split("/")[1])
        node_id = node(c)

        row = [node_id, name, short_name, vlan, terminator, ip2long(ipv4, 4),
               str(ipv4), None, ip2long(ipv4_netmask, 4), str(ipv4_netmask),
               None, ip2long(ipv4_gateway, 4), str(ipv4_gateway),
               None, int(ipv4_netmask_dec), 0]

        c.execute(
            'INSERT INTO network VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
            row)
コード例 #4
0
 def testParseIPv4(self):
     self.assertEquals(processor.ip2long('8.8.8.8', 4), 134744072)
     self.assertEquals(processor.ip2long('77.80.251.247/32', 4), 1297153015)