import requests
import json


def ip_self(app_id, app_secret):
    api_url = f'https://www.mxnzp.com/api/ip/self?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}\n")
    else:
        for key, value in res_text['data'].items():
            print(key.strip().ljust(10), ':', end=' ')
            print(str(value).strip())


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


if __name__ == '__main__':
    main()

