Snippets Project Page
Author: Dazuz
Added: 4y
Updated: Never
mIRC: 7.56
Hits: 1,514
Downloads: 38
Review: westor
Size: 3.21KB
2 0
Login to vote.
Geo Script
v1.1
Tells you the geolocation of a given IPv4 address.
To update the database, type /GEOUPDATE.
To get the geolocation of an IPv4 address, use: $GEOLOCATION(
Database provided by WEBNet77
http://software77.net/geo-ip
Download
JSON
▲ Review
▼ Source
/* Geo Script for mIRC v7.56+ Version: 1.1 Coded by: Dazuz @ QuakeNet To update the database, type /GEOUPDATE. To get the geolocation of an IP address, use: $GEOLOCATION(<IPv4>) Database provided by WEBNet77 http://software77.net/geo-ip 1.1 (2020-03-02) - Fixed /hload error in database update process. - Tidied up the code. 1.0 (2020-02-28) - Initial release. */ on *:load: { if ($version < 7.56) { echo $color(i) -at * Unsupported mIRC version, please update to $v2 or newer. unload -rs $qt($script) } else echo $color(info) -st * Geo Script loaded! } on *:start: { tokenize 1 $qt($scriptdirGeo.db) if ($isfile($1)) hload -m500n geo $1 else geoupdate } on *:unload: { hfree -w geo if ($fopen(g)) .fclose g .remove $qt($scriptdirGeo.db) .remove $qt($scriptdirIpToCountry.csv) } alias geolocation { if ($longip($1) isnum 0-4294967295) { set -l %longip $v1 set -l %lowest 0 set -l %highest $hget(geo,0).item while ($int($calc((%highest +%lowest)/2)) != $1) { tokenize 32 $v1 $hget(geo,$v1) if (%longip isnum $2 - $3) return $4- elseif (%longip < $2) %highest = $1 else %lowest = $1 } return ?? ??? unknown } else return er err error } alias geoupdate { echo $color(i) -st * Geo update: downloading IpToCountry.csv.gz (http://software77.net/geo-ip/?DL=1)... bset -t &header -1 User-Agent: Geo Script noop $urlget(http://software77.net/geo-ip/?DL=1,gb,&data,geo.processupdate,&header) } alias -l geo.processupdate { if ($urlget($1).state == ok) && ($bvar(&data,0)) { echo $color(i) -st * Geo update: IpToCountry.csv.gz downloaded, decompressing... if ($decompress(&data,bm3)) { set -l %file $qt($scriptdirIpToCountry.csv) echo $color(i) -st * Geo update: decompressed, saving to: %file if ($fopen(g)) .fclose g .fopen -o g %file .fwrite -b g &data .fclose g echo $color(i) -st * Geo update: file saved, converting to Geo.db... .timergeoupdate -iom 1 100 geo.updatedb } else geo.error decompression failure. } else geo.error invalid geo response. (State: $urlget($1).state Size: $bvar(&data,0) Reply: $gettok($urlget($1).reply,1,13) $+ ) } alias -l geo.error { echo $color(i) -st * Geo error: $1- beep 3 } alias -l geo.updatedb { unset %s %e %c set -l %i $qt($scriptdirIpToCountry.csv) set -l %o $qt($scriptdirGeo.db) if ($fopen(g)) .fclose g .fopen -o g %o filter -fk %i g "?*","?*","?*","?*","??","???","?*" .fwrite -n g %s %e %c .fclose g unset %s %e %c .remove %i hfree -w geo hload -m500n geo %o echo $color(i) -st * Geo update: %o updated. } alias -l g { tokenize 34 $1 if ($9 $11 $13 == %c) %e = $3 else { if (%c) .fwrite -n g %s %e %c %s = $1 %e = $3 %c = $9 $11 $13 } }
Changelog:
0
0
Review: westor
Nice and useful code, it working perfectly without any bugs, it has a small mirc hang when converting the database but that is only about 5-10 seconds.
Nice and useful code, it working perfectly without any bugs, it has a small mirc hang when converting the database but that is only about 5-10 seconds.
Comments (2)
Mar 16th, 2020 - By: westor
Admin
Just an advise, in lines 41 + 42 you can use an if check to see if the file exists to proceed on remove, because it will cause an error if it doesn't
Change:
.remove $qt($scriptdirGeo.db)
.remove $qt($scriptdirIpToCountry.csv)
To:
if ($isfile($scriptdirGeo.db)) { .remove $qt($scriptdirGeo.db) }
if ($isfile($scriptdirIpToCountry.csv)) { .remove $qt($scriptdirIpToCountry.csv) }
Change:
.remove $qt($scriptdirGeo.db)
.remove $qt($scriptdirIpToCountry.csv)
To:
if ($isfile($scriptdirGeo.db)) { .remove $qt($scriptdirGeo.db) }
if ($isfile($scriptdirIpToCountry.csv)) { .remove $qt($scriptdirIpToCountry.csv) }
Reply:
Mar 17th, 2020 - By: Dazuz
That's by design, it doesn't halt the script and no error is displayed thanks to the dot.
Technically it's a bad practice to do it, but mIRC itself handles it properly, so it would be redundant to do it.
Technically it's a bad practice to do it, but mIRC itself handles it properly, so it would be redundant to do it.