當前位置: 首頁>>代碼示例>>Python>>正文


Python Helper.convertToAsn32方法代碼示例

本文整理匯總了Python中Helper.Helper.convertToAsn32方法的典型用法代碼示例。如果您正苦於以下問題:Python Helper.convertToAsn32方法的具體用法?Python Helper.convertToAsn32怎麽用?Python Helper.convertToAsn32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Helper.Helper的用法示例。


在下文中一共展示了Helper.convertToAsn32方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_summary

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import convertToAsn32 [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
開發者ID:vgiotsas,項目名稱:multilateral,代碼行數:44,代碼來源:BgpParser.py


注:本文中的Helper.Helper.convertToAsn32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。