How To Find Other Web Sites Hosted on a Web Server

Authors: CodeToday | PHP Code | Views: 586 | Posted: 05 AM: 09/05/2017

How To Find Other Web Sites Hosted on a Web ServerCurrently bing.com offers free and unlimited if you use to get websites with the same IP address you can use directly on bing.com by querying https://www.bing.com/.search?q=ip:{ip address} (example: https://www.bing.com/search?q=ip:54.201.226.113) or you can use php code to filter only domain names that are not on bing.com. 





This article uses the following knowledge

  1. file_get_contents: Get data from bing.com, you can use curl_init() instead of file_get_contents
  2. preg_match_all: Parse the text to filter out url links
  3. parse_url: parse url to filter out domain names
We will start with the html form. This form is to get data from input IP

HTML

<form action="" method="post" class="form-horizontal">
<div class="form-group">
<input type="text" name="ip" id="ip" value="<?=$_POST['ip']?>" class="form-control" placeholder = "Enter IP address server here ..." required/>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-info">Find Now</button>
</div>
</form>

After receiving the data from the form will put on the query link on bing.com. https://www.bing.com/search?count=50&q=ip%3A'.$_POST['ip']

Note: you must have an IP prefix: before the ip address in the query and you can add count = [10,20, ...50] to get the number of domains you want

PATTERN

$pattern  = "<as[^>]*href=("??)([^" >]*?)1[^>]*>(.*)</a>"; // filter url

This syntax is used to filter the link contained in the returned data, based on which will filter out the domain name

Source Code PHP

<?
if(isset($_POST['submit'])){

$ipServer = $_POST['ip'];
$content  = file_get_contents('https://www.bing.com/search?count=50&q=ip%3A'.$ipServer);
$pattern  = "<as[^>]*href=("??)([^" >]*?)1[^>]*>(.*)</a>"; // filter url
		
if(preg_match_all("/$pattern/siU", $content, $matches, PREG_SET_ORDER)) {
	
	foreach($matches as $match) {	
		$domain     = parse_url($match[2]);
		$domainHost = $domain[host];
		if($domainHost != 'go.microsoft.com' && $domainHost != 'www.microsofttranslator.com' && $domainHost != '') {
			  
			 $domainServer[] = str_replace('www.','',$domainHost);
			  
		}	
	}
}

print_r( array_unique($domainServer));

}
?>

In addition, you can use the curl_init() function as below

<?php
$url = 'https://www.bing.com/search?count=50&q=ip%3A'.$ipServer;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
?>

Find Other Web Sites Hosted on a Web Server by use RSS

You can use this way, it's easy if you know the xml regular expression. You can use this way, it's easy if you know the xml regular expression. You need to add the format = rss query after the query from bing.com

https://www.bing.com/search?count=50&q=ip%3A'.$ipServer.'&format=rss
PHP code for RSS

$content = file_get_contents('https://www.bing.com/search?count=50&q=ip%3A'.$ipServer.'&format=rss');
$data = new SimpleXmlElement($content);
foreach($data->channel->item as $entry) {
  $title      = $entry->title; // get title
  $link       = $entry->link; // get link
  $des        = $entry->description; // get description
  $domainPath = parse_url($linkDm);
  $domainHost = $domainPath[host];
  echo $domainHost;
}
If you have any questions, please leave a message below