Mengetahui domain yang sering di akses dengan mikrotik - artikel ini akan di bahas cara membuat access log domain yang di akses dari jaringan dengan menggunakan perangkat mikrotik.Dengan begitu kita bisa mengetahui website yang di akses dari jaringan kita.
Requirement
1.Router Mikrotik
2.Web server php dan mysql (lampp/xampp/mamp)
Langkah Membuat statistik domain yang sering di akses dengan mikrotik adalah sebagai berikut
1.Siapkan web server install apache dan mysql
2.Buat database
3.Buat Tabel pada database yang tadi di buat
CREATE TABLE `accesslog` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`domain` varchar(255) NOT NULL,
`ip` varchar(255) NOT NULL,
`jumlah` int(255) NOT NULL,
`tanggal` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1
4.Buat file php di web server dengan script seperti berikut
<?php
$data=$_GET['data'];
if($data!=''){
$servername = "localhost";
$username = "username database";
$password = "password database";
$database = "namadatabase";// Create connection
$conn = new mysqli($servername, $username, $password, $database);// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}$d=explode(' ',$data);
$sql = "SELECT * FROM accesslog where DATE(tanggal)=DATE(NOW())
and ip='".$d['0']."' and
domain='".$d['1']."'
";
$result = $conn->query($sql);if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
$sql="update accesslog set jumlah=jumlah+1
where id='".$row["id"]."'
";
}
} else {
$sql="insert into accesslog set tanggal=NOW(),
ip='".$d['0']."',
domain='".$d['1']."',
jumlah='1'
";
}if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
Selanjutnya kita buat scheduler dan masukkan script berikut pada on event
Buka System>Scheduler pada mikrotik
:do {
:foreach Crec in=[/ip dns cache all find where ( ( (type="A") || (type="CNAME") ) && (static=no))] do={
:local Cname [/ip dns cache get number=$Crec name];
:local Cdata "";
:delay 1000ms;
:if ([/ip dns cache all get $Crec type]="CNAME") do={
:set $Cdata [:resolve $Cname]; } else={
:set $Cdata [/ip dns cache get number=$Crec address];
}
:do {
/tool fetch url="http://192.168.123.254/mikrotiklog/log.php?data=$Cdata%20$Cname" keep-result=no;
}
}
} on-error={:log error message="script failed..."}
Contoh hasi log di server kami
domain ip tanggal Descending jumlah
ms.vdl.wallasleud.com 45.80.38.176 2020-06-25 10:54:12 1
spam.toletavic.com 45.80.38.139 2020-06-25 10:54:10 1
init-p01st.push.apple.com.edgesuite.net 202.4.185.170 2020-06-25 10:54:10 1
metrics.icloud.com 17.248.151.40 2020-06-25 10:54:08 1
mon-va.tiktokv.com.edgesuite.net 202.4.185.97 2020-06-25 10:54:05 1
mon.tiktokv.com.edgesuite.net 202.4.185.73 2020-06-25 10:54:05 1
apollo-singapore.akamaized.net 202.4.185.163 2020-06-25 10:54:05 1
events.appsflyer.com 176.34.131.0 2020-06-25 10:54:02 1
cdn1-production-images-kly.akamaized.net 202.4.185.163 2020-06-25 10:54:01 1
pull-hls-q5.tiktokcdn.com.akamaized.net 184.28.229.17 2020-06-25 10:54:00 1
www.google-analytics.com 74.125.68.100 2020-06-25 10:53:57 1
api.apple-cloudkit.com 17.248.151.72 2020-06-25 10:53:57 1
i.pinimg.com 103.224.141.201 2020-06-25 10:53:57 1
script.hotjar.com 167.71.215.255 2020-06-25 10:53:56 1
cdn4.thumbrio.edgekey.net 23.199.73.225 2020-06-25 10:53:55 1
vc.hotjar.io 68.183.178.67 2020-06-25 10:53:51 1
t.appsflyer.com 34.251.86.30 2020-06-25 10:53:51 1
secure.appex-rf.msn.com.edgekey.net 104.111.134.13 2020-06-25 10:53:50 1
snews.serverhome.com 66.45.246.141 2020-06-25 10:53:48 1
root.aeispeakers.com 52.98.66.104 2020-06-25 10:53:47 1
launches.appsflyer.com 54.77.172.195 2020-06-25 10:53:47 1
ns.metanol.com 66.45.246.141 2020-06-25 10:53:46 1
ecs7.tokopedia.net.edgesuite.net 202.4.185.83 2020-06-25 10:53:45 1
rockydeportes.com.ar 207.38.89.37 2020-06-25 10:53:44 1
webcast16.tiktokv.com.edgekey.net 184.28.229.201 2020-06-25 10:53:43 1
outlook.office365.com 52.98.71.210 2020-06-25 10:53:43 1
zimbra.rockydeportes.com.ar 207.38.89.37 2020-06-25 10:53:42 1
api16-normal-c-alisg.tiktokv.com.edgekey.net 184.28.229.211 2020-06-25 10:53:41 1
bulkrisible.com 89.252.165.22 2020-06-25 10:53:40 1
api16-core-va.tiktokv.com.edgekey.net 184.28.229.240 2020-06-25 10:53:39 1
Dengan begitu kita mengetahui domain yang mungkin akan kita filter sesuai kebutuhan kita sendiri