-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
71 lines (57 loc) · 1.74 KB
/
server.js
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
// server.js
const express = require('express');
const requestIp = require('request-ip');
const useragent = require('useragent');
const dns = require('dns');
const axios = require('axios');
const app = express();
const port = 3000;
// Middleware untuk mendapatkan IP pengguna
app.use(requestIp.mw());
app.use(express.static('public'));
// Handler untuk rute root
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
app.get('/ip-info', async (req, res) => {
const clientIp = req.clientIp;
const userAgent = req.get('user-agent');
const agent = useragent.parse(userAgent);
const browserInfo = {
name: agent.family,
version: agent.major
};
const osInfo = {
name: agent.os.family,
version: agent.os.major
};
// Deteksi informasi DNS (contoh menggunakan google.com)
dns.lookup('google.com', async (err, addresses) => {
if (err) throw err;
const dnsInfo = addresses;
// Deteksi informasi negara berdasarkan IP menggunakan ipinfo.io
const ipInfoResponse = await axios.get(`https://ipinfo.io/${clientIp}?token=YOUR_TOKEN_HERE`);
const ipInfoData = ipInfoResponse.data;
// Mendapatkan kode negara dan bendera dari ipinfo.io
const city = ipInfoData.city;
const region = ipInfoData.region;
const countryCode = ipInfoData.country;
const flagEmoji = countryCode;
// Mengirim informasi sebagai JSON
res.json({
ip: clientIp,
userAgent: userAgent,
browser: browserInfo,
os: osInfo,
dns: dnsInfo,
country: ipInfoData.country,
flag: flagEmoji,
city: city,
region: region
});
});
});
// Menjalankan server pada port tertentu
app.listen(port, () => {
console.log(`Server berjalan di http://localhost:${port}`);
});