diff options
| author | Yuval Adam <_@yuv.al> | 2018-10-12 00:08:27 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-10-12 00:08:27 +0200 |
| commit | 7c5cc0d1fe9cb8ac44848827fdcf78691642c98f (patch) | |
| tree | d6eb180b63f4b0cfea21a2b13714fb92a3528de1 | |
| parent | 31ab92752ae588b76a04eda8d0b58ebaae274ecc (diff) | |
Basic whois subprocess with parsing
| -rw-r--r-- | whois.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/whois.py b/whois.py new file mode 100644 index 0000000..57993f4 --- /dev/null +++ b/whois.py @@ -0,0 +1,13 @@ +from subprocess import run + +def extract_field(field, response): + for line in response: + if line.startswith(field): + return line.split(' ')[-1] + +def whois(ip): + cp = run(['whois', ip], capture_output=True) + lines = cp.stdout.decode().split('\n') + fields = ['route', 'origin'] + res = {f: extract_field(f, lines) for f in fields} + return res |
