代码如下:
import requests, json
access_token = ''
ip_list = []
def saveListToFile(file, list):
"""
将列表逐行写如文件中
:return:
"""
s = '\n'.join(list)
with open(file, 'w') as (output):
output.write(s)
def apiTest():
"""
进行 api 使用测试
:return:
"""
global access_token
page = 1
headers = {'Authorization': 'JWT ' + access_token}
print(access_token)
while True:
try:
r = requests.get(url=('https://api.zoomeye.org/host/search?query="xxx"&facet=app,os&page=' + str(page)), headers=headers)
r_decoded = json.loads(r.text)
for x in r_decoded['matches']:
print(x['ip'] + ':' + str(x['portinfo']['port']))
ip_list.append(x['ip'] + ':' + str(x['portinfo']['port']))
print('[-] info : count ' + str(page * 10))
except Exception as e:
try:
if str(e) == 'matches':
print('[-] info : account was break, excceeding the max limitations')
#break
else:
print('[-] info : ' + str(e))
finally:
e = None
del e
else:
if page == 100: #页数(每页20条)
break
page += 1
def login(user,passwd):
"""
输入用户米密码 进行登录操作
:return: 访问口令 access_token
"""
global access_token
data = {'username':user,
'password':passwd}
data_encoded = json.dumps(data)
try:
r = requests.post(url='https://api.zoomeye.org/user/login', data=data_encoded)
r_decoded = json.loads(r.text)
access_token = r_decoded['access_token']
except Exception as e:
try:
print('[-] info : username or password is wrong, please try again ')
finally:
e = None
del e
apiTest()
saveListToFile('ip.txt', ip_list)
if __name__ == '__main__':username
login('username','passwd')
结果: