import sys
import json
import requests
import time


def ip_check(app_id, app_secret, ip):
    api_url = f"https://www.mxnzp.com/api/ip/aim_ip?ip={ip}&app_id={app_id}&app_secret={app_secret}"
    res = requests.get(api_url)
    res_http_code = res.status_code
    res_text = json.loads(res.text)
    res_code = res_text['code']
    res_msg = res_text['msg']
    if res_http_code != 200 or res_code == 0:
        print(f"接口查询失败：{res_msg}")
    else:
        print('*' * 50)
        for key, value in res_text['data'].items():
            print(key.strip().ljust(10), ':', end=' ')
            print(str(value).strip())
        print()


def main():
    app_id = "nrsngdkvknqkrwko"
    app_secret = "SFFmQWo2dnNBRjdNYkVSclZxa2ZvUT09"

    if len(sys.argv) == 1:
        print("Must specify at least one IP for information check.")
        exit(2)

    # try:
    #     ip = sys.argv[1]
    # except Exception as Err:
    #     print(f"Error Desc: {Err}. Maybe you need to supply correct ip next time.")
    #     exit(2)

    for ip in sys.argv[1:]:
        ip_check(app_id, app_secret, ip)
        time.sleep(1)


if __name__ == '__main__':
    main()

