Recently in improving your programming ability, take some practical gadgets to practice. The script is a Python language that mainly involves module Urllib,json,os modules.
Function: Call Zoomeye API for information
Importurllib.requestImportJSONImportOSdeflogin (): Username= Input ("Username:") Password= Input ("Password:") URL="Https://api.zoomeye.org/user/login"Data= Json.dumps ({'username': Username,'Password':p Assword}) Data_bytes= Bytes (data,'UTF8') Try: Req=urllib.request.Request (url,data_bytes) Response=Urllib.request.urlopen (req) HTML= Response.read (). Decode ('Utf-8') Target=json.loads (HTML) access_token= target['Access_token'] with open ('Access_token.txt','W') as F:f.write (Access_token) f.closePrint('Login seccess!!!') #print (' Your access_token is:%s '% (access_token)) exceptException as err:Print('[info]:username or password is wrong!') defapiget (): whileTrue:host_or_web= Input ("Search for Host or Web: (' q! ' Sign out):") ifHost_or_web = ='q!': BreakQuery= Input ("Input your keyword (-R for your resources-info):") #查看自己的套餐剩余量ifquery = ='- R': Req= Urllib.request.Request ('Https://api.zoomeye.org/resources-info') Ida= Open ('Access_token.txt'). Read () Req.add_header ('Authorization','JWT%s'%(IDA)) re=Urllib.request.urlopen (req) AE= (Re.read (). Decode ('Utf-8')) AE= target =json.loads (AE) dict_web= ae['Resources']['Web-search'] Dict_host= ae['Resources']['Host-search'] Print('your web search:%s'%(dict_web))Print('Your host search:%s'%(dict_host))Else: Try:
Req= Urllib.request.Request ('https://api.zoomeye.org/%s/search?query=%s'%(Host_or_web,query)) IDB= Open ('Access_token.txt'). Read () Req.add_header ('Authorization','JWT%s'%(IDB)) R=Urllib.request.urlopen (req) a= (R.read (). Decode ('Utf-8')) a= target =Json.loads (a)Print('tatal:%s'% (a[' Total'])) forIinchRange (Len (a['matches'])): Print(a['matches'][i]['IP']) exceptException as err:Print('[Erro]:P lease Enter the correct syntax!') defstart ():if notOs.path.isfile ('Access_token.txt'): #首次使用会检查脚本目录下access_token. txt file, no sign-in createsPrint('[info]:you Need login') Login () Apiget ()if __name__=='__main__' : Start ()
Call the Zoomeye API for information