-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoIPLookup.txt
56 lines (45 loc) · 1.67 KB
/
GeoIPLookup.txt
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
Script("Name") = "GeoIP Lookup"
Script("Author") = "Pyro"
Script("Major") = 0
Script("Minor") = 1
Script("Description") = "Looks up the geographic information associated with an IP address or DNS name."
Const LOOKUP_COMMAND = "geoip"
Const LOOKUP_HOSTPARAM = "host"
Sub Event_Load()
Call InitCommands()
End Sub
Sub Event_Command(Command)
If Not Command.Name = LOOKUP_COMMAND Then Exit Sub
host = Command.Argument(LOOKUP_HOSTPARAM)
If Len(host) < 1 Then
Command.Respond "You must specify a hostname to lookup."
Exit Sub
End If
data = scInet.OpenURL(StringFormat("http://freegeoip.net/xml/{0}", host))
Set geoData = CreateObject("Scripting.Dictionary")
lines = Split(data, vbLf)
For i = 1 TO 11
geoData.Add Split(Split(lines(i), "<")(1), ">")(0), Split(Split(lines(i), ">")(1), "</")(0)
Next
If StrComp(host, geoData("IP"), vbTextCompare) <> 0 Then
host = host & " (" & geoData("IP") & ")"
End If
Command.Respond StringFormat("{0} is located in {1}, {2} ({3})", _
host, geoData("City"), geoData("RegionCode"), geoData("CountryName"))
End Sub
Sub InitCommands()
Set cmd = OpenCommand(LOOKUP_COMMAND)
If cmd Is Nothing Then
Set cmd = CreateCommand(LOOKUP_COMMAND)
With cmd
.RequiredRank = 10
.RequiredFlags = "G"
.Description = "Looks up the IP and geographic location of a host."
Set param = .NewParameter(LOOKUP_HOSTPARAM, False, "word")
param.Description = "The hostname to lookup."
.Parameters.Add param
.Save
End With
Set cmd = Nothing
End If
End Sub