本文整理汇总了Python中Helper.Helper.getIPNetwork方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.getIPNetwork方法的具体用法?Python Helper.getIPNetwork怎么用?Python Helper.getIPNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper.Helper
的用法示例。
在下文中一共展示了Helper.getIPNetwork方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_summary
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import getIPNetwork [as 别名]
def parse_summary(ixp, inputfile, ipversion, ixpParam):
"""
Function to parse a BGP summary output file.
It prints the ASN->Neighbor IP mapping in a file
"""
ipToAsn = {}
addrPos, asnPos, ipcountPos, rtrType = [int(ixpParam["summary"]["ip"]), int(ixpParam["summary"]["asn"]),
int(ixpParam["summary"]["ipCount"]), ixpParam["type"]]
with open(inputfile, 'rb') as f:
for line in f:
# split the line to white spaces
lineTokens = line.strip().split()
if len(lineTokens) <= ipcountPos: continue
interfaces = re.findall(
r'(?:\s|^|\(|\[)(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})\.(?:[\d]{1,3})(?:\s|\)|$|\])', line)
if len(lineTokens) > addrPos and len(interfaces) > 0:
# check if the string that is supposed to be in the position of the address is indeed a valid IP address
ip = lineTokens[addrPos]
ipType = Helper.getIPNetwork(ip)
if str(ipType) == str(ipversion) or (ipType > 0 and int(ipversion) == 10):
# check if the string in the position of the ASN is a valid number
asn = lineTokens[asnPos]
asn = asn.replace("AS", "")
if '.' in asn:
asn = Helper.convertToAsn32(asn)
if Helper.isPositiveInt(asn):
# check if the ASN is active and advertises prefixes
# often the number of advertised prefixes may be split in total received/best
# in this case we want the total which is the first of the two numbers
ipcount = lineTokens[ipcountPos]
try:
if rtrType == "bird":
received = re.findall(r"[\w']+", ipcount)[0]
elif rtrType == "quagga":
received = ipcount
except:
print ipcount
# if string represents a valid positive number add asn->ip mapping to the dictionary
if Helper.isPositiveInt(received):
if ip not in ipToAsn:
ipToAsn[ip] = asn
return ipToAsn