bgp- research & experiments with border gateway protocol |
git clone git://git.acid.vegas/bgp.git |
Log | Files | Refs | Archive | README |
ip_asn_pyipmeta.py (2974B)
1 __author__ = "Pooja Pathak" 2 __email__ = "<pmpathak@ucsd.edu>" 3 # This software is Copyright © 2020 The Regents of the University of 4 # California. All Rights Reserved. Permission to copy, modify, and 5 # distribute this software and its documentation for educational, research 6 # and non-profit purposes, without fee, and without a written agreement is 7 # hereby granted, provided that the above copyright notice, this paragraph 8 # and the following three paragraphs appear in all copies. Permission to 9 # make commercial use of this software may be obtained by contacting: 10 # 11 # Office of Innovation and Commercialization 12 # 13 # 9500 Gilman Drive, Mail Code 0910 14 # 15 # University of California 16 # 17 # La Jolla, CA 92093-0910 18 # 19 # (858) 534-5815 20 # 21 # invent@ucsd.edu 22 # 23 # This software program and documentation are copyrighted by The Regents of 24 # the University of California. The software program and documentation are 25 # supplied “as is”, without any accompanying services from The Regents. The 26 # Regents does not warrant that the operation of the program will be 27 # uninterrupted or error-free. The end-user understands that the program 28 # was developed for research purposes and is advised not to rely 29 # exclusively on the program for any reason. 30 # 31 # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 32 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, 33 # INCLUDING LOST PR OFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 34 # DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF 35 # THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY 36 # DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 37 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 38 # SOFTWARE PROVIDED HEREUNDER IS ON AN “AS IS” BASIS, AND THE UNIVERSITY OF 39 # CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 40 # ENHANCEMENTS, OR MODIFICATIONS. 41 42 #!/usr/bin/env python 43 44 import _pyipmeta 45 import datetime 46 import os 47 import psutil 48 49 def returnTime(): 50 return datetime.datetime.now() 51 52 def returnMemUsage(): 53 process = psutil.Process(os.getpid()) 54 return process.memory_info()[0] 55 56 57 ipm = _pyipmeta.IpMeta() 58 # print(ipm) 59 60 # print("Getting/enabling pfx2as provider (using included test data)") 61 prov = ipm.get_provider_by_name("pfx2as") 62 # print(prov) 63 print(ipm.enable_provider(prov, "-f /test/pfx2as/routeviews-rv2-20170329-0200.pfx2as.gz")) 64 print() 65 66 67 ips = [] 68 with open('ips.txt') as f: 69 for line in f: 70 line = line.rstrip().split("\t")[1] 71 ips.append(line) 72 73 begin_time = returnTime() 74 begin_mem = returnMemUsage() 75 76 ip2asn = {} 77 for ip in ips: 78 if ipm.lookup(ip): 79 (res,) = ipm.lookup(ip) 80 if res.get('asns'): 81 ip2asn[ip] = res.get('asns') 82 83 84 # print(ip2asn) 85 end_time = returnTime() 86 end_mem = returnMemUsage() 87 88 # hour:minute:second:microsecond 89 print("Delta time:" , end_time - begin_time) 90 print("Delta memory:", end_mem - begin_mem)