Created
September 4, 2017 15:03
-
-
Save imlonghao/61d715cd4aaa19f0dfe3090de82eaf3d to your computer and use it in GitHub Desktop.
Get all the aut-num from as-set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Copyright (c) 2017 imlonghao <[email protected]> | |
# | |
# 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