hey there. this is my first script that im submitting here.
simply put, it:
gets the ip of a website
encodes each number to binary
makes sure each binary string has 8 characters
combines each binary string
decodes the 32 bit binary string into a link
questions, comments, and flaming accepted
(although i wouldnt like the flaming too much)
<?php
/**********************************************
* by kryptn | kryptn@gmail.com | kryptn.com
* usage: $var = get_site_addr(www.example.com)
**********************************************/
// gets web address if it is set
$web = isset($_REQUEST['web']) ? gethostbynamel($_REQUEST['web']) : null;
// form block
$html = <<<html
<div align=center>
<form action=''>
<input type=text name=web><br>
<input type=submit value=go>
</form>
</div>
html;
// calls function for ip
if(isset($web))
// if is set then a link to the modified site is displayed, along with the html block
echo '<div align="center"><a href="http://'.get_site_addr($web).'">'.$web.'</a></div>'.$form;
else
// any other way then it just displays the html block
echo $html;
function get_site_addr($web){
// sets the default value for $num
$num = '';
// for every character in the variable $web, it does this loop
for($ipa=0; isset($web[$ipa]); $ipa++){
// if the character is a period (.) then it assigns the connected value to $ip_1
// array and resets $num to the default value
if($web['ipa'] == '.'){
$ip_1[] = $num;
$num = '';
}
// adds on to $num with the character its testing
else
$num .= $web[$ipa];
}
// for every entry in $ip_1 it does this loop
foreach($ip_1 as $key => $bin){
// encodes from decimal to binary (4 => 100)
$ip_bin = decbin($bin);
// makes sure that there is eight characters in the string
// if not, it adds a zero to the beginning
$ip_bin = substr("00000000",0,8 - strlen($ip_bin)) . $ip_bin;
// re-assigns the encoded binary to another array.
// i need to work on this one
$ip_2[] = $ip_bin;
}
// puts the four values for the $ip_2 array into one string
$bin = $ip_2[0].$ip_2[1].$ip_2[2].$ip_2[3];
// makes sure that $bin is 32 characters in length
if(strlen($bin) == '32'){
// decodes the 32 bit binary string into a decimal number
$ip = bin_dec($bin);
// returns the value of ip so $ip = get_site_addr($site); works
return $ip;
}
}
?>