$userIP = $GLOBALS["REMOTE_ADDR"];
$octets = explode(".",$userIP);
$val = ereg_replace("$octets[3]","0",$octets[3]);
$subnet = "$octets[0]";
$subnet .= ". $octets[1]";
$subnet .= ". $octets[2]";
$subnet .= " .";
echo "eg. $subnet$val/24";
$nmapipaddr = $subnet$value/24;
This code will take an IP address: for example and explode the address at each . and replace the last octet of the IP to .0/24
The above snippet of code can be used to pass a value to the function below.
function nmap_pc($nmapipaddr) {
$time=date("H:i:s");
$date=date("d-m-Y");
$nmap = "/usr/local/bin/nmap $nmapipaddr -sP";
$command = "$nmap";
echo "NMAP ran against: $nmapipaddr ";
echo "<BR>";
echo "$date @ $time";
echo "<P>";
@exec($command, $dd, $result);
$dd[] = $dd -1;
$indexLimit = count($dd);
for($index=0; $index < $indexLimit; $index++) {
$orts = (" $dd[$index] ");
echo (" $orts<BR> ");
}
}
nmap_pc($nmapipaddr);
Using ereg_replace() function to process data.
I used it in a function that I wroted to get IP addresses...
function get_ips($mhost,$community) {
global $ipoctet,$db_server,$db_user,$db_passwd,$db_name;
$mib_str = "at.atTable.atEntry.atPhysAddress";
/* get Data using snmpwalkoid*/
$_mibvars = snmpwalkoid("$mhost","$community","$mib_str");
/*
Output example ;
at.atTable.atEntry.atPhysAddress.1.1.136.xxx.xxx.1 = Hex: 00 00
X2 X6 XD XD
at.atTable.atEntry.atPhysAddress.1.1.136.xxx.xxx.47 = Hex: 00 C0
4X 8X 9X DX
*/
for (reset($_mibvars); $i =
key($_mibvars); next($_mibvars)) {
/* Process Results */
$ip =
eregi_replace("$mib_str.[^s].[^s^s].$ipoctet","$ipoctet","$i");
$ip = ereg_replace("\"","","$ip");
$mac = ereg_replace("Hex:","","$_mibvars[$i]");
$mac = ereg_replace("\"","","$mac");
/* Insert data into database */
$mac = chop($mac);
$query = "REPLACE INTO ip_mac (ipaddr,mac_addr) VALUES
('$ip','$mac')";
$macaddr_res = mysqlquery($db_name,$query);
if(!empty($macaddr_res)) {
echo "<META
CONTENT=\"0; URL=./ipdb.php\" HTTP-EQUIV=\"REFRESH\">";
}else{
echo mysql_error(http://www.pccs-linux.com/spacer.gif) . "<br>\n";
}
}
} // End of Function
>> Comments/FeedBack
|