I am trying to write a script in python where it would search the data and return the IP addresses and the data that goes with them, but I would like to filter the search so it would return just the IP addresses and their HTTP status, just the first line, not the whole section with the complete data.
This is the code that I have:
import shodan
SHODAN_API_KEY = 'API Key'
api = shodan.Shodan(SHODAN_API_KEY)
try:
results = api.search('http', page=1, limit=10)
print ('Results found: %s' % results['total'])
for result in results['matches']:
print ('IP: %s' % result['ip_str'] + ' - ' + 'HTTP: %s' % result['data'])
print ('')
except shodan.APIError as e:
print ('Error: %s' % e)
This is the output I am getting:
Results found: 236280753
IP: 98.129.229.204 - HTTP: HTTP/1.1 200 OK Server: Apache/2.4 Content-Type: text/html; charset=UTF-8 Date: Sun, 11 Dec 2022 19:29:48 GMT Accept-Ranges: bytes Connection: Keep-Alive Set-Cookie: X-Mapping-hjggddoo=22C05A3A99FA43E436FE707A7C0D13DD; path=/ Last-Modified: Tue, 10 Sep 2019 00:23:11 GMT Content-Length: 201
So what I am trying to get is just the IP addresses and the HTTP status from result['data']
if at all possible?