python 应用 IPy 计算IP/掩码的网络地址

来源:互联网 发布:淘宝新规则2016年9月 编辑:程序博客网 时间:2024/05/16 12:01

python 应用 IPy 计算IP/掩码的网络地址


from IPy import IP

def ipnetwork(ip, mask):
    return IP(ip).make_net(mask)


def issamenetwork(ip1, mask1, ip2, mask2):
    return ipnetwork(ip1, mask1) == ipnetwork(ip2, mask2)


con=sqlite3.connect(":memory:")
con.create_function("IPAddCheck",4,issamenetwork)
cur=con.cursor()
cur.execute("""
    select * 
    from table1 
    join table2 on 1=1
    and IPAddCheck(table1.ip,table1.mask, table2.ip, table2.mask)
    """)

0 0
原创粉丝点击