namp端口监控导入mysql【单文件版】

很早以前写的代码,写出来以备忘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$mysql_server_name='localhost';
$mysql_username='';
$mysql_password='';
$mysql_database='';
$link = mysqli_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
mysqli_set_charset ($link,'utf8');
if(!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
function CheckEmptyString($C_char){
if (!is_string($C_char)) return false;
if (empty($C_char)) return false;
if ($C_char=='') return false;
return true;
}
$xml = simplexml_load_file("nmap.xml");
foreach ($xml as $host => $value) {
if((string)$host == "host"){
$addr = (string) $value->address["addr"];
echo $addr;
$str1='';
foreach ($value->ports->port as $port){
if (CheckEmptyString($port) == false){
$ports = $port["portid"].",";
$str1 = $str1.$ports;
}
}
$str2 = trim($str1,',');
$sql = "insert into port (ip,port,date) VALUES ('$addr','$str2',now())";
mysqli_query($link,$sql);
}
}
echo "\r\nend!!";
?>

Author: 1314mylove
Link: https://blog.1314mylove.com/2018/04/namp端口监控导入mysql【单文件版】/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.