Jump to content

PHP Code To Find Server Details ?


d.shankar

Recommended Posts

all you need to do is call the home page of the domain (assuming it's a web server). Included in the headers sent back is the info you are looking for. I'd use curl functions, but you may get away with file functions to just pull a page back and parse the headers.

I did this a while ago, and found my old code and it was like this (It was to get a weather part of weather.com), yours will be simpler probably

<?php 
if($content=file_get_contents("http://www.weather.com/outlook/recreation/outdoors/fishing/28911:21")){
$content = substr_replace($content,"",0,2000);//Strips out the first css idderation
$css_start = strpos($content,"<style type=\"text/css\">")-1;
$css_end = strpos($content,"</style>");
$css_length = $css_end-$css_start;
$css = substr($content,$css_start,$css_length);
echo $css."</style>";
$start = strpos($content,"<!-- main module -->")-1;
$end = strpos($content,"<!-- end today / tonight -->");
$length = $end-$start;
$data = substr($content,$start,$length);
}
?>

 

I broke apart the source code to what I wanted.

Yours will be like

<?php
$server = "";
if($content=file_get_contents("http://samspade.org/whois/".$server)){
$content = explode("<div class=\"set\"", $content); //This breaks it up at the start of the raw data
$data = explode("</div>",$content[1]); //This gets the end chopped off
echo $data[0];
}
?>

Then just do what you want with $data[0] to get what you want

 

this is what i've hashed out in a few minutes using the samspade result (it only does the first box, but can be modified for the second box)  it returns this array of each of the heading names so you could just pull what you need out of that

<?php
$server = "google.com";
if($content=file_get_contents("http://samspade.org/whois/".$server)){
$content = explode("<div class=\"set\"", $content); //This breaks it up at the start of the raw data
$data = explode("</div>",$content[1]); //This gets the end chopped off
$fields = array(
	"Registrant", "Domain Name", "Registrar Name", "Registrar Whois",
	"Registrar Homepage", "Administrative Contact", "Technical Contact Zone",
	"Created On", "Expires On", "Record last updated on", "Domain servers in listed order"
);
$data_2 = array();
$i = 0;
$field_count = count($fields)-1;
while(!empty($fields[$i])){
	$j = $i+1;
	$tempdata = explode($fields[$i],$data[0]);
	if($j <$field_count){
		$tempdata_2 = explode($fields[$j],$tempdata[1]);
		$temp = trim(nl2br(str_replace(": ", "", $tempdata_2[0])));
		$data_2[$fields[$i]] = $temp;
	}
	else{
		$temp = trim(nl2br(str_replace(": ", "", $tempdata[1])));
		$data_2[$fields[$i]] = $temp;
	}
$i++;
}
foreach($data_2 as $key => $value){
	echo $key.": ".$value."<br/>";
}
}
else{
echo "failed to open stream";
}
?>

I found a few small issues in the fields array causing a bit of issues which i fixed

<?php
$server = "google.com";
if($content=file_get_contents("http://samspade.org/whois/".$server)){
$content = explode("<div class=\"set\"", $content); //This breaks it up at the start of the raw data
$data = explode("</div>",$content[1]); //This gets the end chopped off
$fields = array(
	"Registrant", "Domain Name", "Registrar Name", "Registrar Whois",
	"Registrar Homepage", "Administrative Contact", "Technical Contact  Zone Contact",
	"Created ", "Expires ", "Record last updated ", "Domain servers in listed order"
);
$data_2 = array();
$i = 0;
$field_count = count($fields)-1;
while(!empty($fields[$i])){
	$j = $i+1;
	$tempdata = explode($fields[$i],$data[0]);
	if($j <=$field_count){
		$tempdata_2 = explode($fields[$j],$tempdata[1]);
		$temp = trim(nl2br(str_replace(": ", "", $tempdata_2[0])));
		$data_2[$fields[$i]] = $temp;
	}
	else{
		$temp = trim(nl2br(str_replace(": ", "", $tempdata[1])));
		$data_2[$fields[$i]] = $temp;
	}
$i++;
}
foreach($data_2 as $key => $value){
	echo $key.": ".$value."<br/>";
}
}
else{
echo "failed to open stream";
}
?>

 

It still needs some work like cleaning up the created on register on modified on fields, and the nameserves to remove the ad space, and also it needs to be turned into a function rather than the static code, but  I think u got the idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.