通过接口批量查询该ip是否属于指定接口
import requests
import json
if __name__ == "__main__":
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'
}
with open('./ip.txt','r') as fp:
list_ip = fp.readlines()
for li in list_ip:
li = li.rstrip()
url="http://www.xxxx.com/api/query_ip?ip={0}&flag=1&key=cdbcbdhbhcbdhcbhdbchdbchdbch&user=root".format(li)
result_json = requests.get(url, headers=headers)
if result_json.json()['total'] == 0:
cw_url="http://www.sss.cn/api/query_ip?ip={0}&flag=1&key=fjdifjdifncjdnjcndjhfjndjnjdhfjdhj&user=root".format(li)
cw_result_json = requests.get(cw_url,headers=headers)
print("XXX科技CMDB未发现该资产 ->",end="")
if cw_result_json.json()['total']==0:
print(li + " <- SSSSCMDB未发现该资产")
print(result_json.json(),cw_result_json.json())
else:
print("该资产属于SSSSCMDB:")
ip1 = cw_result_json.json()['data'][0]['ip1']
company = cw_result_json.json()['data'][0]['company']
profile_center = cw_result_json.json()['data'][0]['profit_center']
platform = cw_result_json.json()['data'][0]['platform']
leader = cw_result_json.json()['data'][0]['leader']
email = cw_result_json.json()['data'][0]['email']
print(ip1 + ' ' + company + ' ' + profile_center + ' ' + platform + ' ' + leader + ' ' + email)
else:
ip1 = result_json.json()['data'][0]['ip1']
company = result_json.json()['data'][0]['company']
profile_center = result_json.json()['data'][0]['profit_center']
platform = result_json.json()['data'][0]['platform']
leader = result_json.json()['data'][0]['leader']
email = result_json.json()['data'][0]['email']
print(ip1 + ' ' + company + ' ' + profile_center + ' ' + platform + ' ' + leader + ' ' + email)
|