验证中...
Languages: Python
Categories: 常用工具包
Latest update 2019-10-12 14:39
comm.py
Raw Copy
tcpIpCodes = ["ICMP","IGMP","GGP","IP","ST","TCP","CBT","EGP","IGP","BBN-RCC-MON","NVP-II","PUP","ARGUS","EMCON","XNET","CHAOS","UDP","MUX","DCN-MEAS","HMP","PRM","XNS-IDP","TRUNK-1","TRUNK-2","LEAF-1","LEAF-2","RDP","IRTP","ISO-TP4","NETBLT","MFE-NSP","MERIT-INP","SEP","3PC","IDPR","XTP","DDP","IDPR-CMTP","TP++","IL","IPv6","SDRP","IPv6-Route","IPv6-Frag","IDRP","RSVP","GRE","MHRP","BNA","ESP","AH","I-NLSP","SWIPE","NARP","MOBILE","TLSP","SKIP","IPv6-ICMP","IPv6-NoNxt","IPv6-Opts","","CFTP","","SAT-EXPAK","KRYPTOLAN","RVD","IPPC","","SAT-MON","VISA","IPCV","CPNX","CPHB","WSN","PVP","BR-SAT-MON","SUN-ND","WB-MON","WB-EXPAK","ISO-IP","VMTP","SECURE-VMTP","VINES","TTP","NSFNET-IGP","DGP","TCF","EIGRP","OSPFIGP","Sprite-RPC","LARP","MTP","AX.25","IPIP","MICP","SCC-SP","ETHERIP","ENCAP","","GMTP","IFMP","PNNI","PIM","ARIS","SCPS","QNX","A/N","IPComp","SNP","Compaq-Peer","IPX-in-IP","VRRP","PGM","","L2TP","DDX","IATP","STP","SRP","UTI","SMP","SM","PTP","ISIS","FIRE ","CRTP","CRUDP","SSCOPMCE ","IPLT ","SPS","PIPE","SCTP","FC","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""]
def find_index(func, l):
for idx, li in enumerate(l):
if func(li):
return idx
return -1
def protoToCode(proto):
if isinstance(proto, str) is not True:
return -1
if proto.lower() == 'any' or proto == '0':
return 0
if re.match(r'^\d{1,3}$', proto) is not None:
if int(proto) >=0 and int(proto) < 255:
return int(proto)
else:
return -1
else:
for i, tc in enumerate(tcpIpCodes):
if tc.lower() == proto.lower():
return (i+1)
return -1
def dict_factory(cur, row):
d = {}
for idx,col in enumerate(cur.description):
d[col[0]] = row[idx]
return d
#sql查询函数
def queryDb(dbconn, query, args=(), one=False):
dbconn.row_factory = dict_factory
cur = dbconn.cursor()
res = cur.execute(query, args)
rest = res.fetchall()
cur.close()
return (rest[0] if rest else None) if one else rest

Comment list( 0 )

You need to Sign in for post a comment

Help Search