Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $query = 'ShodanQuery';
- $loginArgs = array(
- 'username' => 'shodan_username',
- 'password' => 'shodan_password',
- 'grant_type' => 'password',
- 'continue' => 'https://account.shodan.io/',
- 'login_submit' => 'Log+in'
- );
- fetchUrl('https://account.shodan.io/login', $loginArgs);
- $summary = fetchUrl("https://www.shodan.io/search/_summary?query=$query");
- preg_match_all('/<div class="span8 name"><a title="(.*)" href=".*<\/a>/', $summary, $matches);
- $countries = array(
- $matches[1][0],
- $matches[1][1],
- $matches[1][2],
- $matches[1][3],
- $matches[1][4]
- );
- $pageMax = fetchUrl("http://www.shodan.io/search?query=$query&page=6");
- $pageMax = strpos($pageMax, 'more than 5 pages') ? 5 : 5000;
- foreach($countries as $country)
- {
- for($pageNum = 1; $pageNum <= $pageMax; $pageNum++)
- {
- $pageData = fetchUrl("http://www.shodan.io/search?query=$query+country:$country&page=$pageNum");
- preg_match_all('/<div class="ip"><a href="(.*)">.*<\/a>.*/', $pageData, $matches);
- if(count($matches[1]) == 0)
- {
- break;
- }
- foreach($matches[1] as $match)
- {
- $return[$country][] = $match;
- }
- }
- if(count($matches[1]) == 0)
- {
- break;
- }
- }
- echo serialize($return);
- // FetchUrl Function
- function fetchUrl($url, $data = '', $referer = '')
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie');
- curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- if(is_array($data))
- {
- $fields = '';
- foreach($data as $key => $value)
- {
- $fields .= $key . '=' . $value . '&';
- }
- rtrim($fields, '&');
- curl_setopt($ch, CURLOPT_POST, count($data));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement