-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
78 lines (63 loc) · 2.98 KB
/
index.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
71
72
73
74
75
76
77
78
//Dependencies
const Request = require("request")
const Is_IP = require("is-ip")
const Chalk = require("chalk")
const Fs = require("fs")
//Variables
const Self_Args = process.argv.slice(2)
const Max_Request = parseInt(Fs.readFileSync("./max_request.txt", "utf8"))
var IPTracker_Data = {}
IPTracker_Data.requests = 0
//Main
if(Self_Args.length == 0){
console.log(`${Chalk.grey("[") + Chalk.redBright("ERROR") + Chalk.grey("]")} Invalid IP.`)
process.exit()
}
if(!Is_IP(Self_Args[0])){
console.log(`${Chalk.grey("[") + Chalk.redBright("ERROR") + Chalk.grey("]")} Invalid IP.`)
process.exit()
}
console.log(`${Chalk.grey("[") + Chalk.blueBright("INFO") + Chalk.grey("]")} Please wait, While I'm tracking the IP.`)
if(Max_Request > 1500){
console.log(`${Chalk.grey("[") + Chalk.redBright("ERROR") + Chalk.grey("]")} Invalid IP/The API limit has exceeded please wait 1 hour to use this again.`)
process.exit()
}
Request(`https://freegeoip.app/json/${Self_Args[0]}`, function(err, res, body){
if(err){
console.log(`${Chalk.grey("[") + Chalk.redBright("ERROR") + Chalk.grey("]")} Invalid IP.`)
process.exit()
}
IPTracker_Data.requests += 1
body = JSON.parse(body)
if(res.statusCode != 200){
console.log(`${Chalk.grey("[") + Chalk.redBright("ERROR") + Chalk.grey("]")} Invalid IP/The API limit has exceeded please wait 1 hour to use this again.`)
process.exit()
}
console.log(Chalk.greenBright(`IP: ${body.ip}
Country Name: ${(body.country_name != "" ? body.country_name : "Unable to find the IP country name.")}
Country Code: ${(body.country_code != "" ? body.country_code : "Unable to find the IP country code.")}
Region Name: ${(body.region_name != "" ? body.region_name : "Unable to find the IP region name.")}
Region Code: ${(body.region_code != "" ? body.region_code : "Unable to find the IP region code.")}
City: ${(body.city != "" ? body.city : "Unable to find the IP city.")}
Timezone: ${(body.time_zone != "" ? body.time_zone : "Unable to find the IP timezone.")}
ZipCode: ${(body.zip_code != "" ? body.zip_code : "Unable to find the IP zipcode.")}
Metro Code: ${(body.metro_code != "" ? body.metro_code : "Unable to find the IP metro code.")}
Latitude: ${(body.latitude != "" ? body.latitude : "Unable to find the IP latitude.")}
Longitude: ${(body.longitude != "" ? body.longitude : "Unable to find the IP longitude.")}`))
})
process.on("SIGINT", function(req, res){
if(Max_Request == 0){
Fs.writeFileSync("./max_request.txt", IPTracker_Data.requests.toString(), "utf8")
}else{
Fs.writeFileSync("./max_request.txt", (IPTracker_Data.requests += Max_Request).toString(), "utf8")
}
process.exit()
})
process.on("beforeExit", function(req, res){
if(Max_Request == 0){
Fs.writeFileSync("./max_request.txt", IPTracker_Data.requests.toString(), "utf8")
}else{
Fs.writeFileSync("./max_request.txt", (IPTracker_Data.requests += Max_Request).toString(), "utf8")
}
process.exit()
})