Created
March 31, 2019 17:26
-
-
Save yas-nyan/f844791b5bdc6d2209a7e98064bf8e52 to your computer and use it in GitHub Desktop.
最新のNGNのネットワークアドレスを取得するスクリプト
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
import ipaddress | |
import subprocess | |
import requests | |
DNS_SERVER = "2404:1a8:7f01:b::3" # NTT西は所定のDNSサーバー | |
DOMAIN = "route-info.flets-east.jp" # NTT西管内は route-info.flets-west.jp | |
PORT = 49881 | |
# dig IPv6 addr | |
dig_res = subprocess.run(["dig",f"@{DNS_SERVER}",DOMAIN,"AAAA","+short"],stdout=subprocess.PIPE) | |
ipv6_addr = dig_res.stdout.decode("utf8").rstrip("\n") | |
# GET route info | |
headers = {"Host": f"{DOMAIN}:49881","Accept":"*/*","Accept-Charset":"utf-8","Connection":"close"} | |
get_res = requests.get(f"http://[{ipv6_addr}]:{PORT}/v6/route-info",headers=headers) | |
# formatting | |
raw_arr = get_res.content.decode("utf-8").replace("\r\n",",").replace(" ", ",").split(",") | |
# ip networkにならないものを消す | |
res_arr = [] | |
for element in raw_arr: | |
try: | |
_net = ipaddress.ip_network(element) | |
res_arr.append(element) | |
except: | |
continue | |
print(res_arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment