Skip to content

Instantly share code, notes, and snippets.

@imlonghao
Created September 4, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imlonghao/61d715cd4aaa19f0dfe3090de82eaf3d to your computer and use it in GitHub Desktop.
Save imlonghao/61d715cd4aaa19f0dfe3090de82eaf3d to your computer and use it in GitHub Desktop.
Get all the aut-num from as-set
#!/usr/bin/env python3
#
# Copyright (c) 2017 imlonghao <shield@fastmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import subprocess
import re
base = 'AS-IMLONGHAO'
r_as = re.compile('members:\s+AS(\d+)')
r_as_set = re.compile('members:\s+(AS-.+)')
as_list = []
as_set_list = [base]
while as_set_list != []:
as_set = as_set_list[0]
as_set_list.pop(0)
process = subprocess.Popen(['/usr/bin/whois', '-B', as_set], stdout=subprocess.PIPE)
result = process.communicate()[0].decode()
as_list += r_as.findall(result)
as_set_list += r_as_set.findall(result)
for i in set(as_list):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment