0
IPアドレスを国コードに変換するPythonスクリプト。 情報はウェブサイト 'https://freegeoip.net/json/'から取得されます。国コードPythonでスクリプトを見つける
これ以外の方法はありますか?
import json
import requests
import subprocess
# clearing the screen.
subprocess.call('clear',shell=True)
msg = 'country code finder'
# Making the header.
print('')
print(' ',msg.upper())
print(' ','-' * len(msg))
print('')
lookup_ip = input(' Enter Your Ip Address : ')
# Fetching the country code from 'https://freegeoip.net/json/'
# The reply will be in json format.
try:
lookup_string = 'https://freegeoip.net/json/'+lookup_ip
reply = requests.get(lookup_string)
geodata= json.loads(reply.text)
print('')
print(' Country Is ::' , geodata['country_code'])
print('')
except:
print(' Unable to Fetch', lookup_string)
print('')
質問がありますか? – Cfreak
http://codereview.stackexchange.com/に属しているため、この質問を議論の対象外としています – kdopen