/
nmapbaru.php
74 lines (64 loc) · 3.5 KB
/
nmapbaru.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
function debug($string) {
for ($i=0;$i<strlen($string);$i++) {
echo substr($string, $i,1) . ' = ' . $i . ' ' . ord(substr($string, $i,1)) . '<br>';
}
}
function showData($data) {
echo '<table style="border:100"><tr><th>IP</th><th>MAC</th></tr>';
for ($i=0;$i<count($data['MAC']);$i++) {
echo '<tr><td>' . $data['IP'][$i] . '</td><td>' . $data['MAC'][$i] . '</td></tr>';
}
echo '</table';
}
function update($data) {
$server = 'localhost';
$user = 'root';
$password = '';
$database = 'db_absenv2';
$koneksi= mysql_connect($server, $user, $password);
mysql_select_db($database, $koneksi);
for ($i=0;$i<count($data['MAC']);$i++) {
$sql= "INSERT INTO MACaddrs(mac_address, ip_address)
VALUES('" . $data['MAC'][$i] . "', '" . $data['IP'][$i] . "')";
mysql_query($sql);
}
}
// echo '<tr><td>' . $data['IP'][$i] . '</td><td>' . $data['MAC'][$i] . '</td></tr>';
//echo '</table';
function getMac($string) {
$data = array();
$count = 0;
//string untuk mengekstrak MAC
$mac = substr($string,strpos($string, 'MAC Address:'));
//string untuk mengekstrak IP
$ip = substr($string,strpos($string, 'Nmap scan report for 192')+21);
while ($count < 14) {
$data['MAC'][] = substr($mac, 13, 17);
$data['IP'][] = substr($ip, 0, strpos($ip,'Host')-1);
//echo 'MAC = '. substr($mac, 13, 17) . '<br> IP =' . substr($ip, 0,strpos($ip,'Host')-1) . '<br>';
$string = substr($mac,strpos($mac, 'Nmap scan report for 192'));
$mac = substr($string,strpos($string, 'MAC Address:'));
$ip = substr($string,strpos($string, 'Nmap scan report for 192')+21);
$check = substr($mac, 13, 3);
if (strcmp($check,'ort') == 0) {
//echo "Keluar";
break;
}
$count++;
}
return $data;
}
ob_start();
system('nmap -sP 192.168.0.1/24');
$res = ob_get_contents();
ob_clean();
//echo $res;
//echo $res;
$test = "Nmap scan report for 192.168.1.1 Host is up (0.0020s latency). MAC Address: F8:1A:67:FF:88:B4 (Tp-link Technologies) Nmap scan report for 192.168.0.2 Host is up (0.10s latency). MAC Address: B0:E8:92:F7:7E:CC (Seiko Epson) Nmap scan report for 192.168.0.101 Host is up (0.13s latency). MAC Address: 7C:F9:0E:05:96:AC (Samsung Electronics) Nmap scan report for 192.168.0.104 Host is up (0.024s latency). MAC Address: 00:24:21:E6:04:B7 (Micro-star Int'l) Nmap scan report for 192.168.0.106 Host is up (0.21s latency). MAC Address: A0:F3:C1:0B:80:24 (Tp-link Technologies) Nmap scan report for 192.168.0.107 Host is up (0.22s latency). MAC Address: A0:F3:C1:0B:80:24 (Tp-link Technologies) Nmap scan report for 192.168.0.110 Host is up (0.072s latency). MAC Address: 18:CF:5E:27:4C:1E (Liteon Technology) Nmap scan report for 192.168.0.113 Host is up (0.074s latency). MAC Address: 28:E3:47:D1:D9:5F (Liteon Technology) Nmap scan report for 192.168.0.116 Host is up (0.079s latency). MAC Address: 00:1E:65:B4:DE:AC (Intel Corporate) Nmap scan report for 192.168.0.120 Host is up (0.11s latency). MAC Address: 00:18:60:6C:43:0D (SIM Technology Group Shanghai Simcom,) Nmap scan report for 192.168.0.124 Host is up (0.082s latency). MAC Address: 88:53:2E:11:57:83 (Intel Corporate) Nmap scan report for 192.168.0.127 Host is up (0.087s latency). MAC Address: DC:85:DE:8A:B6:E9 (Azurewave Technologies.) Nmap scan report for 192.168.0.133 Host is up (0.088s latency). MAC Address: A0:F3:C1:20:52:75 (Tp-link Technologies) Nmap scan report for 192.168.0.100 Host is up. Nmap done: 256 IP addresses (14 hosts up) scanned in 4.47 seconds ";
//getMac($test);
$data = getMac($res);
//showData($data);
showData($data);
update($data);
?>