python - Shodan. Get all open ports for a net -


i want open ports network shodan (i know can use nmap want carry out shodan).

the problem website shows "top services", , given services.

for example, net: 195.53.102.0/24 given following ports:

top services http 15 https 2 dns 2 ftp 2 ike-nat-t 1 

but if scan net: 195.53.0.0/16, given these ports:

top services http 1,012 https 794 179 290 ike 238 ike-nat-t 227 

so missing services dns , ftp.

i trying api, python:

import shodan  shodan_api_key = "xxxxxxxxxxxxxxxxxxxxxxx"  api = shodan.shodan(shodan_api_key)  # wrap request in try/ except block catch errors try:      # search shodan       results = api.search('net:195.53.102.0/24')     service in results['matches']:         print service['ip_str']         print service['port']  except shodan.apierror, e:         print 'error: %s' % e 

and results get:

195.53.102.193 80 195.53.102.138 80 195.53.102.148 80 195.53.102.136 80 195.53.102.157 80 195.53.102.226 443 195.53.102.66 500 195.53.102.133 80 195.53.102.142 80 195.53.102.66 4500 195.53.102.141 80 195.53.102.131 21 195.53.102.152 53 195.53.102.153 21 195.53.102.209 80 195.53.102.132 53 195.53.102.226 80 195.53.102.147 80 195.53.102.142 443 195.53.102.178 80 195.53.102.135 143 195.53.102.146 80 195.53.102.143 80 195.53.102.144 80 

just 1 port per ip, , example, ip: 195.53.102.131 has ports 21, 80 , 443 open, results just:

195.53.102.131 21 

instead of:

195.53.102.131 21 80 443 

so want either to, website, given ports/services instead of top services or, api, being able ports per ip, not 1. or if has better solution, hear too.

as said, perform shodan, not nmap. thank in advance.

when use api.search() method, shodan searches service banner , service banner has 1 port. if want return ports host, should use api.host() instead. example:

import shodan  shodan_api_key = "xxxxxxxxxxxxxxxxxxxxxxx"  api = shodan.shodan(shodan_api_key)  # wrap request in try/ except block catch errors try: # search shodan     results = api.search('net:195.53.102.0/24')     service in results['matches']:         hostinfo = api.host(service['ip_str'])          print service['ip_str']         #not sure if it's correct, should something,         #like this:         port in hostinfo['port']:             print port  except shodan.apierror, e:     print 'error: %s' % e 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -