ipwhoisを使ってwhoisで得られる情報を得る


ykishi@dezembro X-Forwarded-For % cat whois_test.py 
#!/usr/bin/env python3

from ipwhois import IPWhois
import json
import sys


def get_info(ip):

  obj = IPWhois(ip)
  whoisInfo = obj.lookup_whois()

  # print(type(whoisInfo))

  name = whoisInfo["nets"][0]["name"]
  country = whoisInfo["nets"][0]["country"]

  return name, country


if __name__ == "__main__":

  result = get_info("51.103.36.90")
  print(type(result))
  print(result)
  print(",".join(result))
  print(result[0])
  print(result[1])
ykishi@dezembro X-Forwarded-For % ./whois_test.py 
<class 'tuple'>
('MICROSOFT', 'GB')
MICROSOFT,GB
MICROSOFT
GB
ykishi@dezembro X-Forwarded-For %