diff --git a/ripedb/asset_ilines.py b/ripedb/asset_ilines.py index cae7e73..2f7addc 100755 --- a/ripedb/asset_ilines.py +++ b/ripedb/asset_ilines.py @@ -4,10 +4,13 @@ and transform a comma separated list of AS-SETs (-as-sets) into IRCnet's I-Line structure. It will look at all ipv4 and ipv6 route objects in a certain AS number, and it finds the AS numbers by expanding the AS-SET -members. It uses the class speficied on the commandline (-class) +members. It uses the class speficied on the commandline (-class). You can +also use the flag -asns to specify a list of AS numbers. These two flags +can be combined or used in isolation (as is shown by the examples below. Example usage: $ asset_ilines.py -as-sets AS-IP-MAN-PEERING-CIXP,AS-IP-MAN-PEERING-TIX \ -class 210 -output ilines.as-set.conf +$ asset_ilines.py -asns 8404,20932 -class 220 -output ilines.asn.conf """ import getopt @@ -22,7 +25,8 @@ import re def usage(): print """Usage: -h (-help): Help, this message - -a (-as-sets): The (comma separeted list of) AS set(s) to resolve + -a (-as-sets): A (comma separeted list of) AS set(s) to lookup + -l (-asns): A (comma separated list of) AS numbers to lookup -o (-output): The output file to write -y (-class): The Y-line class to put the I line in (default: 200)""" pass @@ -83,8 +87,8 @@ def asset_to_asn(_asset, _whois_server = "whois.ripe.net", def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "ha:o:y:", - ["help", "assets=", "output=", "class="]) + opts, args = getopt.getopt(sys.argv[1:], "ha:l:o:y:", + ["help", "assets=", "asns=", "output=", "class="]) except getopt.GetoptError, err: print str(err) # will print something like "option -foo not recognized" usage() @@ -94,13 +98,22 @@ def main(): "AS-IP-MAN-PEERING-SWISSIX"] _class = 200 _output = None + _asns = [20932] for o,a in opts: if o == "-h" or o == "-help": usage() sys.exit(2) elif o == "-a" or o == "-as-sets": - _assets = a.split(',') + if a == '': + _assets = [] + else: + _assets = a.split(',') + elif o == "-l" or o == "-asns": + if a == '': + _asns = [] + else: + _asns = a.split(',') elif o == "-o" or o == "-output": _output = a elif o == "-y" or o == "-class": @@ -115,9 +128,10 @@ def main(): if type(_class) != types.IntType: usage() assert False, "-y (-class) must be an integer" - if len(_assets) < 1: + if len(_assets) < 1 and len(_asns) < 1: usage() - assert False, "-a (-as-sets) must be a list of AS-SETs" + assert False,("-a (-as-sets) or -l (-asns) must be a comma " + "separated list") try: ofile = open(_output, "w") @@ -133,6 +147,12 @@ def main(): continue _data['asn'][_asn] = [] + _data['as-set']['LOCAL'] = _asns + for _asn in _data['as-set']['LOCAL']: + if _asn in _data['asn']: + continue + _data['asn'][_asn] = [] + all_route_list = [] for _asn in _data['asn'].keys(): route_list = asn_to_route (_asn) @@ -150,8 +170,8 @@ def main(): (time.asctime(time.localtime(time.time())), getpass.getuser(), socket.gethostname())) ofile.write("# Commandline: %s\n" % ' '.join(sys.argv)) - ofile.write("# assets=%s output=%s class=%s\n" % - (','.join(_assets), _output, _class)) + ofile.write("# assets=%s asns=%s output=%s class=%s\n" % + (','.join(_assets), ','.join(_asns), _output, _class)) ofile.write("# Objects found: %d route/route6, %d ASn, %d as-set\n\n" % (len(all_route_list), len(_data['asn']), len(_assets)))