Index: admin_nmap_input.php
===================================================================
--- admin_nmap_input.php (revision 1251)
+++ admin_nmap_input.php (working copy)
@@ -38,6 +38,7 @@
$timestamp = date("YmdHis");
$uuid = "";
$process = "";
+$host_down = false;
$sql = "SET @@session.sql_mode=''";
$result = mysql_query($sql);
@@ -47,6 +48,7 @@
$input = explode("\n", $input);
foreach ($input as $split) {
+
if (substr($split, 0, 12) == "MAC Address:") {
// OK - we have a hit.
$mac = substr($split,13,17);
@@ -62,7 +64,7 @@
$device_type = ltrim(rtrim($temp2[0]));
echo "Device Type: " . $device_type . "
";
}
- if (substr($split, 0, 8) == "Running:") {
+ if (substr($split, 0, 7) == "Running") {
// OK - we have a hit.
$temp = explode(":", $split);
$running = ltrim(rtrim($temp[1]));
@@ -163,138 +165,160 @@
echo "Name: " . $name . "
";
}
}
+ if (substr(trim($split), -11) == "[host down]") {
+ echo "Host Down.";
+ $host_down = true;
+ }
} // End of for each
- if ($device_type == ""){$device_type = "unknown";}
- if ($running == ""){$running = "unknown";}
- if (substr_count($device_type, "general purpose") > "0"){
- if (substr_count($running, "Linux") > "0") { $device_type = "os_linux";}
- if (substr_count($running, "Windows") > "0") { $device_type = "os_windows"; echo "Windows.
";}
- if (substr_count($running, "unix") > "0") { $device_type = "os_unix";}
- if (substr_count($running, "MAC") > "0") { $device_type = "os_mac";}
- if (substr_count($running, "AIX") > "0") { $device_type = "os_unix";}
- if (substr_count($running, "SCO UnixWare") > "0"){ $device_type = "os_unix";}
- } else {}
+
+ if ($host_down == false) {
+ if ($device_type == ""){$device_type = "unknown";}
+ if ($running == ""){$running = "unknown";}
+ if (substr_count($device_type, "general purpose") > "0"){
+ if (substr_count($running, "Linux") > "0") { $device_type = "os_linux";}
+ if (substr_count($running, "Windows") > "0") { $device_type = "os_windows"; echo "Windows.
";}
+ if (substr_count($running, "unix") > "0") { $device_type = "os_unix";}
+ if (substr_count($running, "MAC") > "0") { $device_type = "os_mac";}
+ if (substr_count($running, "AIX") > "0") { $device_type = "os_unix";}
+ if (substr_count($running, "SCO UnixWare") > "0"){ $device_type = "os_unix";}
+ } else {}
- if (isset($mac) AND $mac <> "00:00:00:00:00:00"){
- // First check the network_card table
- $sql = "SELECT net_uuid FROM network_card WHERE net_mac_address = '" . $mac . "'";
- echo $sql . "
";
- $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
- $myrow = mysql_fetch_array($result);
- if (isset($myrow["net_uuid"])){
- $process = "network_mac";
- $uuid = $myrow["net_uuid"];
- } else {
- // Not in network_card - check other table
- $sql = "SELECT other_id, other_mac_address FROM other WHERE other_mac_address = '" . $mac . "' OR other_ip_address = '" . ip_trans_to($ip_address) . "' ORDER BY other_timestamp";
- echo $sql . "
";
- $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
- $myrow = mysql_fetch_array($result);
- if (isset($myrow["other_id"])){
- $process = "other_mac";
- $uuid = $myrow["other_id"];
- if ($myrow["other_mac_address"] <> ""){$mac = $myrow["other_mac_address"];}
- }
- }
- } else {}
+ if (isset($mac) AND $mac <> "00:00:00:00:00:00"){
+ // First check the network_card table
+ $sql = "SELECT net_uuid FROM network_card WHERE net_mac_address = '" . $mac . "'";
+ echo $sql . "
";
+ $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
+ $myrow = mysql_fetch_array($result);
+ if (isset($myrow["net_uuid"])){
+ $process = "network_mac";
+ $uuid = $myrow["net_uuid"];
+ echo "UUID set to " . $uuid . " from net_uuid field of network_card
";
+ } else {
+ // Not in network_card - check other table
+ $sql = "SELECT other_id, other_mac_address FROM other WHERE other_mac_address = '" . $mac . "' OR other_ip_address = '" . ip_trans_to($ip_address) . "' ORDER BY other_timestamp";
+ echo $sql . "
";
+ $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
+ $myrow = mysql_fetch_array($result);
+ if (isset($myrow["other_id"])){
+ $process = "other_mac";
+ $uuid = $myrow["other_id"];
+ echo "UUID set to " . $uuid . " from other_id field of other
";
+ if ($myrow["other_mac_address"] <> ""){$mac = $myrow["other_mac_address"];}
+ }
+ }
+ } else {}
- if ($mac == "00:00:00:00:00:00"){
- $sql = "SELECT net_uuid FROM network_card WHERE net_ip_address = '" . ip_trans_to($ip_address) . "'";
- echo $sql . "
";
- $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
- $myrow = mysql_fetch_array($result);
- if (isset($myrow["net_uuid"])){
- $process = "network_ip";
- $uuid = $myrow["net_uuid"];
- } else {
- $sql = "SELECT other_id FROM other WHERE other_ip_address = '" . ip_trans_to($ip_address) . "'";
- echo $sql . "
";
- $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
- $myrow = mysql_fetch_array($result);
- if (isset($myrow["other_id"])){
- $process = "other_ip";
- $uuid = $myrow["other_id"];
- } else {}
- }
- } else {}
+ if ($mac == "00:00:00:00:00:00"){
+ $sql = "SELECT net_uuid FROM network_card WHERE net_ip_address = '" . ip_trans_to($ip_address) . "'";
+ echo $sql . "
";
+ $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
+ $myrow = mysql_fetch_array($result);
+ if (isset($myrow["net_uuid"])){
+ $process = "network_ip";
+ $uuid = $myrow["net_uuid"];
+ } else {
+ $sql = "SELECT other_id FROM other WHERE other_ip_address = '" . ip_trans_to($ip_address) . "'";
+ echo $sql . "
";
+ $result = mysql_query($sql) or die ('Query Failed:
$sql
' . mysql_error() . '
' . $sql);
+ $myrow = mysql_fetch_array($result);
+ if (isset($myrow["other_id"])){
+ $process = "other_ip";
+ $uuid = $myrow["other_id"];
+ } else {}
+ }
+ } else {}
- if ($uuid == "" and $mac <> "00:00:00:00:00:00") {
- // Insert into other table
- $sql = "INSERT INTO other (other_network_name, other_ip_address, other_mac_address, ";
- $sql .= "other_description, other_manufacturer, other_type, ";
- $sql .= "other_timestamp, other_first_timestamp) VALUES (";
- $sql .= "'$name','" . ip_trans_to($ip_address) . "','$mac',";
- $sql .= "'$running','$manufacturer','$device_type',";
- $sql .= "'$timestamp','$timestamp')";
- $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
- $uuid = mysql_insert_id();
- $process = "new_other";
- echo $sql . "
";
- } else {}
+ if ($uuid == "" and $mac <> "00:00:00:00:00:00") {
+ // Insert into other table
+ $sql = "INSERT INTO other (other_network_name, other_ip_address, other_mac_address, ";
+ $sql .= "other_description, other_manufacturer, other_type, ";
+ $sql .= "other_timestamp, other_first_timestamp) VALUES (";
+ $sql .= "'$name','" . ip_trans_to($ip_address) . "','$mac',";
+ $sql .= "'$running','$manufacturer','$device_type',";
+ $sql .= "'$timestamp','$timestamp')";
+ $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
+ $uuid = mysql_insert_id();
+ $process = "new_other";
+ echo $sql . "
";
+ }
+
+ if ($uuid == "" and $mac == "00:00:00:00:00:00") {
+ // Insert into other table without MAC
+ $sql = "INSERT INTO other (other_network_name, other_ip_address, ";
+ $sql .= "other_description, other_manufacturer, other_type, ";
+ $sql .= "other_timestamp, other_first_timestamp) VALUES (";
+ $sql .= "'$name','" . ip_trans_to($ip_address) . "',";
+ $sql .= "'$running','$manufacturer','$device_type',";
+ $sql .= "'$timestamp','$timestamp')";
+ $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
+ $uuid = mysql_insert_id();
+ $process = "new_other_no_mac";
+ echo $sql . "
";
+ }
- if ($process == "other_mac"){
- $sql = "UPDATE other SET other_ip_address = '". ip_trans_to($ip_address) . "', ";
- $sql .= "other_mac_address = '$mac', other_timestamp = '$timestamp' ";
- $sql .= "WHERE other_id = '$uuid'";
- $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
- //$uuid = mysql_insert_id();
- $process = "update_other";
- echo $sql . "
\n";
- } else {}
+ if ($process == "other_mac"){
+ $sql = "UPDATE other SET other_ip_address = '". ip_trans_to($ip_address) . "', ";
+ $sql .= "other_mac_address = '$mac', other_timestamp = '$timestamp' ";
+ $sql .= "WHERE other_id = '$uuid'";
+ $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
+ //$uuid = mysql_insert_id();
+ $process = "update_other";
+ echo $sql . "
\n";
+ } else {}
- if ($process <> ""){
- // Process the file
- echo "UUID: " . $uuid . "
";
- echo "Process: " . $process . "
";
- $sql = "DELETE FROM nmap_ports WHERE nmap_other_id = '" . $uuid . "'";
- echo $sql . "
\n";
- $result = mysql_query($sql) or die ('Delete Failed:
' . $sql . '
' . mysql_error());
- foreach ($input as $split) {
- // Search every row for tcp/udp open or open|filtered ports
- if (strpos($split, "open") === false) {
- } else if ((strpos($split, "/tcp") === false) and (strpos($split, "/udp") === false)) {
- } else {
- $temp = explode(" ", $split);
- $temp1 = explode("/", $temp[0]);
- $port_number = $temp1[0];
- $port_proto = $temp1[1];
- $pos = strlen($temp[0]) + 1;
- while (substr($split, $pos, 1) == " ") {
- $pos++; }
- $temp = substr($split, $pos);
- $temp1 = explode(" ", $temp);
- $port_state = $temp1[0];
- $pos = $pos + strlen($port_state);
- while (substr($split, $pos, 1) == " ") {
- $pos++; }
- $temp = substr($split, $pos);
- $temp1 = explode(" ", $temp);
- $port_name = $temp1[0];
- $pos = $pos + strlen($port_name);
- while (substr($split, $pos, 1) == " ") {
- $pos++; }
- $port_version = rtrim(substr($split, $pos));
- if ($port_version == "") {
- $port_version = "Not detected"; }
- else { }
+ if ($process <> ""){
+ // Process the file
+ echo "UUID: " . $uuid . "
";
+ echo "Process: " . $process . "
";
+ $sql = "DELETE FROM nmap_ports WHERE nmap_other_id = '" . $uuid . "'";
+ echo $sql . "
\n";
+ $result = mysql_query($sql) or die ('Delete Failed:
' . $sql . '
' . mysql_error());
+ foreach ($input as $split) {
+ // Search every row for tcp/udp open or open|filtered ports
+ if (strpos($split, "open") === false) {
+ } else if ((strpos($split, "/tcp") === false) and (strpos($split, "/udp") === false)) {
+ } else {
+ $temp = explode(" ", $split);
+ $temp1 = explode("/", $temp[0]);
+ $port_number = $temp1[0];
+ $port_proto = $temp1[1];
+ $pos = strlen($temp[0]) + 1;
+ while (substr($split, $pos, 1) == " ") {
+ $pos++; }
+ $temp = substr($split, $pos);
+ $temp1 = explode(" ", $temp);
+ $port_state = $temp1[0];
+ $pos = $pos + strlen($port_state);
+ while (substr($split, $pos, 1) == " ") {
+ $pos++; }
+ $temp = substr($split, $pos);
+ $temp1 = explode(" ", $temp);
+ $port_name = $temp1[0];
+ $pos = $pos + strlen($port_name);
+ while (substr($split, $pos, 1) == " ") {
+ $pos++; }
+ $port_version = rtrim(substr($split, $pos));
+ if ($port_version == "") {
+ $port_version = "Not detected"; }
+ else { }
- echo "
Port found.
";
- echo "Port: " . $port_number . "
";
- echo "Protocol: " . $port_proto . "
";
- echo "State: " . $port_state . "
";
- echo "Service: " . $port_name . "
";
- echo "Version: " . $port_version . "
";
+ echo "
Port found.
";
+ echo "Port: " . $port_number . "
";
+ echo "Protocol: " . $port_proto . "
";
+ echo "State: " . $port_state . "
";
+ echo "Service: " . $port_name . "
";
+ echo "Version: " . $port_version . "
";
- $sql = "INSERT INTO nmap_ports (nmap_other_id, nmap_port_number, nmap_port_proto, nmap_port_name, nmap_port_version, nmap_timestamp) VALUES (";
- $sql .= "'" . $uuid . "','" . $port_number . "','" . $port_proto . "','" . $port_name . "','" . $port_version . "','" . $timestamp . "')";
- $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
- echo "
" . $sql . "
";
- }
- }// End of foreach
- }//End of if ($process <> "")
+ $sql = "INSERT INTO nmap_ports (nmap_other_id, nmap_port_number, nmap_port_proto, nmap_port_name, nmap_port_version, nmap_timestamp) VALUES (";
+ $sql .= "'" . $uuid . "','" . $port_number . "','" . $port_proto . "','" . $port_name . "','" . $port_version . "','" . $timestamp . "')";
+ $result = mysql_query($sql) or die ('Insert Failed:
' . $sql . '
' . mysql_error());
+ echo "
" . $sql . "
";
+ }
+ }// End of foreach
+ }//End of if ($process <> "")
+ }
-
//echo "
" .$sql . "
";