GeoIP script - Page 3
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

GeoIP script

Started by VidFamne, 13 April, 2004, 15:03:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chill

oh now i got ya, alright, well I wouldn't care about 32 MB, but my guess is that its way more, but tell me the site where to download the IP-ranges with city, and I'll try to reduce memory used by lua as much as i can.
And maybe split the table like vidfamne does into 10 tables then it will be only a 10th of the reduced memory, we'll see.

[PT]CableGuy

#51
QuoteOriginally posted by chill
...but tell me the site where to download the IP-ranges with city...
:( I'm sorry. "Those" DataBases are NOT for free.
I don't even know how it works since i dont have 100$$$ right now. :(
AnalyseSpider.com - IP-Country-Region-City mapping Database


This one , claims to have: (199$$$) :(
"Database size 30 MB and contains details of over 140 million of Ip addresses".
Ipmessages.com Country & ISP by IP Address


I've found this one and it's free: :D (save it as an html file)

  
       
  
    
      
    

They have flags also !!!! Unfortunatly , no database... :(

chill

I also searched the net, and to have constant access to a updated db, is bets to query the whois databases, since they get updated every day and its for free.
else I think country is enough.

[PT]CableGuy

QuoteOriginally posted by chill
...else I think country is enough....
Well , if were talking about "internacional networks" , i must agree with you. :D

BUT...can you imagine , if in a "nacional hub" , you could discover "real neighboors" in the same hub ?
I mean..."Hey , you are from Lisbon to...probably we could meet sometime ?"  :D

This should be (also) awesome to "design a map" of "nacional users connectivity". :rolleyes:
And use it , to make "nacional statistics" of our users.
I now , i'm probably "thinking loud" and abusing from "you scripters"....
...but ideias come for free and i love to share them. :]

Thanks again , for this amazing script and for all "yours" dedication on this forum.  :D

chill

mem 13 MB
need time to startup at first but then its fast
only reads from disk once

geoIP v 004

Sudds

looks good im gonna try it but them memory is alot lol does it use much bandwith?
Sudds

chill

#56
Sudds, if you look up in this thread there is a less memory wasting script, but it reads from disc, each time you query a IP, so you can descide yourself, mem and performance vs. less mem and less performance,
its a choice for what it should do, like if you show users country on connect, I would pick more mem, if you only need it a few times per day I'd choose less mem.

Ahm and the bandwidth used is the text sent, shouldn't be much

Herodes

I was thinking something about this script as I was going throught the thread ....

Would it be possible for the GeoIp tables to be eliminated at a counter progressive way ...

To give what I mean in a better way lets take an example ...

Lets say there is this Public Hub that is based for example in Italy and
it mainly receives users/ips from Italy ...
Shouldn't the ips from China, if not used then
be erased 'gradualy' and at the end if they are not used at some set time period they should be eliminated ...
A simple overwrite of the tables would then be enough to bring them back ...

If a Chinese user logs on then, instead of
the GeoIp info (that would in other case appear),
appears his IP ...
Then for curiosity It could be taken up to the curious to resolve ... :D

Basically I am talking about adaptational GeoIp list.
That adapts by removing "reduntant"(not used) Ip/Ip ranges
 in order to free up mem ..

I hope its clear ..

VidFamne

#58
Here's a little extended GeoIP script.
Its exprimental, so be aware,  it might stress really busy hubs;
--GeoIP-script by VidFamne (2004-05-25)
--Type +Country  or  and get the Country and CountryCode from a User
--Type +TopCountry to get Country Stats.
--Added a small welcome message, which show how many compatriot they've got in hub.
--The GeoIP database is from MaxMind GeoIP database GeoIPCountryCSV


function Main()
	tCnumb = {}
	f = "GeoIPtables/Cnumb.txt"
	OpConnected=NewUserConnected
	OpDisconnected=UserDisconnected
	dofile(f)
end

function OnExit()
	save(f, tCnumb)
end

function DataArrival(curUser, sData) 
      local s,e,cmd,arg = strfind( sData, "^%b<>%s+(%S+)%s*(%S*)|$" )
		if (cmd=="+TopCountry") then
		local curtime = date()
	  	SendToNick(curUser.sName,"\r\n") 
          	SendToNick(curUser.sName,"\tTOP COUNTRY\t\t("..curtime..")")
	  	SendToNick(curUser.sName,strrep("=-",34))
          	local Index = sorting(tCnumb) 
            		for i = 1, Index.n do 
              		local key = Index[i] 
              		SendToNick(curUser.sName, "**** "..i.." :   "..format("%-6s %-12s %-6s","~~~",tCnumb[key],key)) 
              		SendToNick(curUser.sName,strrep("-",90))
			if i>=15 then break end            
          		end 
		return 1 
		elseif (cmd=="+Country") then
	   	local T, nick, compIp = clock(), GetItemByName(arg), 0
		if nick then
		compIp = ComputeIP(nick.sIP)
		elseif strfind(arg,"^%d+%.%d+%.%d+%.%d+") then
		compIp = ComputeIP(arg)
		else
			SendToNick(curUser.sName,"**** "..arg.." isn't in our records****") return 1 
			end 
				if compIp==2130706433 then 
				SendToNick(curUser.sName,"**** "..arg.." is sitting on localhost") return 1 
				end
				local C, CC = tSearchCountry(compIp)
					if C == "" then
					SendToNick(curUser.sName,"**** "..arg.." isn't in our records****") return 1
					else
					SendToNick(curUser.sName,"****SearchTime; "..format("%3.2f",(clock()-T)).." sec.") 
					SendToNick(curUser.sName,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]")
					return 1
					end
		
		end
end

function sorting(table) 
  local index = {n=0} 
  foreach(table, function(key, value) tinsert(%index, key) end)
  local func = function(a, b) return %table[a] > %table[b] end
  sort(index, func) return index 
end

function NewUserConnected(curUser)
	local compIp = ComputeIP(curUser.sIP)
	local C = tSearchCountry(compIp)
	tCnumb[C] = tCnumb[C] or 0
	tCnumb[C] = tCnumb[C] + 1
	local Countn = tCnumb[C]-1
	SendToNick(curUser.sName," Hello "..curUser.sName.."! You're from "..C.." and You have "..Countn.." compatriot in this hub.")
	curUser:SendData("Sending you this hubs normal user-command. Right-klick on hub tab or userlist.|$UserCommand 255 7|$UserCommand 0 1|$UserCommand 1 1 Get Country Stats.$<%[mynick]> +TopCountry||")
end

function UserDisconnected(curUser)
	local compIp = ComputeIP(curUser.sIP)
	local C = tSearchCountry(compIp)
	tCnumb[C] = tonumber(tCnumb[C]) - 1
end

function save(f, table)
	local f = openfile(f,"w+")
	local table = tCnumb	
	write(f, "tCnumb = {\n") 
	for key, value in table do 
	write(f, '\t["'..key..'"] = '..value..',\n')
	end 
	write(f, "\t}")
	closefile(f)
end


function tSearch(nr)

  local tGeoIpRangefile = ""
  local nr = tonumber(nr)
  local tTables = { [1] = { [1] = "GeoIPtables/1.lua", [2] = 33996344, [3] = 1081403871 },
	      	    [2] = { [1] = "GeoIPtables/2.lua", [2] = 1081403872, [3] = 2212298751 },
	            [3] = { [1] = "GeoIPtables/3.lua", [2] = 2212364288, [3] = 3233791231 },
	            [4] = { [1] = "GeoIPtables/4.lua", [2] = 3233791232, [3] = 3262479610 },
	            [5] = { [1] = "GeoIPtables/5.lua", [2] = 3262479611, [3] = 3278943819 },
	            [6] = { [1] = "GeoIPtables/6.lua", [2] = 3278943820, [3] = 3389026559 },
	            [7] = { [1] = "GeoIPtables/7.lua", [2] = 3389026560, [3] = 3480612351 },
	            [8] = { [1] = "GeoIPtables/8.lua", [2] = 3480612352, [3] = 3559682095 },
	            [9] = { [1] = "GeoIPtables/9.lua", [2] = 3559682096, [3] = 3585048575 },
	            [10] = { [1] = "GeoIPtables/10.lua", [2] = 3585048576, [3] = 3737124863 }
	  }
		for i = 1, 10 do
			if nr >= tTables[i][2] and nr <= tTables[i][3] then
			tGeoIpRangefile = tTables[i][1]
			break
			end
		end
	 	return tGeoIpRangefile
end
	


function ComputeIP(IP)
	local _,_,a,b,c,d = strfind(IP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
	if a and b and c and d then
		return a*16777216 + b*65536 + c*256 + d
	end
end

----the Binary Search Algo----

function tSearchCountry(num)
  local num = tonumber(num)
  local tGeoIpRangefile = tSearch(num)
  dofile(tGeoIpRangefile)
    if tGeoIpRange == nil then
    return 1 end
  local C = ""
  local CC = ""
  local low=1
  local mid = tonumber(mid)
  local high=getn(tGeoIpRange)

	while low <= high  do
		mid = floor((low+high)/2)
		if  tGeoIpRange[mid][1] <= num and num <= tGeoIpRange[mid][2]  then 
		C = tGeoIpRange[mid][4]
		CC = tGeoIpRange[mid][3] 
		break 
		end		  
			if tGeoIpRange[mid][1] > num then 
			high = mid-1
			else low = mid+1
			end
	end
   	tGeoIpRange = nil
     	collectgarbage()
	return C,CC
end

--------------------------VidFamne

pipdipchip

Looks nice VidFamne but this is what I get:

[02:16]    TOP COUNTRY      (06/16/04 02:16:15)
[02:16] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[02:16] **** 1 :   ~~~    2            1    
[02:16] ------------------------------------------------------------------------------------------
[02:16] **** 2 :   ~~~    1            1    
[02:16] ------------------------------------------------------------------------------------------

VidFamne

Hi pipdipchip :)
Have you the "old" database-files in the script folder?
Otherwise, please download "GeoIP script ver.4.01"
from the 'Script Archive hosted by Optimus'
and replace 'Countryscript.lua' with this new one.
Sorry for I didnt mention that. ;)

VidFamne

GeoIP script ver.4.11
Updated the 'database files' with over 3000 new ip-ranges
and some changes in code.
Added a welcome message.
Added $Usercommand.
The files is on "Script Archive hosted by Optimus" .

nEgativE

QuoteOriginally posted by VidFamne
GeoIP script ver.4.11
Updated the 'database files' with over 3000 new ip-ranges
and some changes in code.
Added a welcome message.
Added $Usercommand.
The files is on "Script Archive hosted by Optimus" .

ei VidFamne, great work here.. tell me, can i just update the database files ? :)

And.. where are the files ? i just can't find them :| Hehe..

VidFamne

Yes, you can update the 'database files' with the new ones.
But you had to replace the old  "function tSearch(nr)" with the new one.
Can be downloaded >>HERE<<

nEgativE

#64
VidFamne, tks.. i decided to run that version 4.11, it's dam good, now.. i just have a lot of syntax erros.. at the function UserDisconnected, this only with fakers that are banned by iprange.. and users without tag i thing .. is there anyway to solve ? :))

VidFamne

Havent think of this ;))
Here is a quickie, dont know if it solve the problem though;
function UserDisconnected(curUser)
	local compIp = ComputeIP(curUser.sIP)
	if compIp then else
	return 1 end
	local C = tSearchCountry(compIp)
	tCnumb[C] = tCnumb[C] - 1
end
use this instead.

VidFamne

#66
Merged Top 10 into GeoIP script, and used RabidWombat's
howto parse commands in the DataArrival() function.
UserCommands wich are sent to user;
Get Country stats.,
TopOnliner,
TopChatter,
TopBanner,
TopKicker,
MyTime,
Get User's Country,
Get User's Time.
And for Operators theres an extra command;
Clean log  ------------to clean out if there is some "orphan items" in the
login- and timetable for varies reasons
Please remove all files in Saves-folder when restart HUB
Dont remove files in Saves-folder when restart SCRIPT
Can be downloaded >>HERE<<
Updated the GeoIP database, from MaxMind.
It now contains 64 905 IP-ranges.
Added UserCommand +myip also. :)

[PT]CableGuy

EXCELENT JOB VidFamme  !!!
I'm trully amazed....what can i say ? I'll sure use it in "our" network.Thanks a million !!!

VidFamne

Thanks for the appreciation [PT]CableGuy :)
And >>HERE<<  is a new update.
The database from MaxMind now contains  65 502 IP-ranges.
Some minor changes in code as I tried to implement "proper tail calls"
in DataArrival() . Dont know if it gains any performance though.

BottledHate

i get errors when i try to open the rar...

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

VidFamne

#70
Sorry, I have corrected the link now.
Please try to download again.

UwV

#71
Very nice, really
 .. but one strange thing i notice ..

[23:50:08] ------------------------------------------------------------------------------------------
[23:50:08] ****  11     ~~~    1            Denmark              
[23:50:08] ------------------------------------------------------------------------------------------
[23:50:08] ****  12     ~~~    1            1                    
[23:50:08] ------------------------------------------------------------------------------------------
[23:50:08] ****  13     ~~~    1            Finland              
[23:50:08] ------------------------------------------------------------------------------------------


what country is 1 ?

 and a request (2 actually)..

is possible to have a version to do only the county thingy.. (no kick/chat/ban/online-stats) and maybe possible to have a option to tag the users with their "..CC.." ?

\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

VidFamne

#72
>>HERE<<   is the version with only the
country 'thingy' ;D
About  tagging, the nicks or in the description, I think it
would stress the hub to much. I'll have to think about it.
**Edit** a minor bugfix

UwV

#73
hehe thanks ,,,
this verson looks pretty simular to what i run now .. .. exept .. there is a looot of line wich have  -- in front of them .. ;0)
(yes i had already 'stripped' the functions i didn't need  but this is much 'cleaner' )
couldn't find the "old geo-ip script" myself ..
Thank you :0)

about he tag (in description).. it is just that i have seen it done ..
by hawk's latest "monster sccript"
 But .. it's.. compiled :0(
and only works in combination with functions i don't want again from that script ..
\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

UwV

#74
hi VidFrame
i have "downgraded"  to the "upgraded" tt + c v1.422

first on one hub (0.3.3.0 b 15.25 with CB5 as main script) and .. very very happy..
just ..
Syntax error: bad argument #1 to `closefile' (invalid file handle)
stack traceback:
   1:  function `closefile' [C]
   2:  method `save' at line 44 [file `Files/Func/fFunc.lua']
   3:  function `OnExit' at line 13 [file 'scripts\top ten + country1.lua']
well i can live with that iwas thinking .. just clean the table myself if i must ..
so i then did the same on an other hub, (0.3.6 TD 4.99 with RC9 as main script)
and i get this ..
Syntax Error: attempt to perform arithmetic on a nil value (once in a while..)
-- and loads of these :
Syntax Error: table index is nil
any suggestions ..

P.S. i have tried: yes file/no file , with empty table/no-table/singlevalue in table   etc. etc.
many hub-reboots to try and solve it .. :0(
but no luck yet ..
\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

SMF spam blocked by CleanTalk