Call the Zoomeye API for information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.