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)
""")
http://hi.baidu.com/tim_spac/item/97bb3c1b545c64761009b582