GeoIP script
 

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.

VidFamne

Put up this in this forum too, cause I dont know which the right one :)
**Link removed**

Hades

#1
Top ten works fine!
...
However geo-ip that i waited so long for doesn't seenm to work in my hub:((
after +Country chatmessage:isn't in our records
Or should i use +Country ?
....
I'm running couple of scripst there possibly there might be a script conflict?

VidFamne

#2
Hi Hades! :)

I dont know what you have expected from the GeoIP script.
But you just type +Country and then the name of a user,
to get the Country user from, and his/hers CountryCode.
Sorry if I've disapponted you.

yepyepyep4711

GeoIP is working great.

I get the following error on top ten though:

Syntax error: attempt to perform arithmetic on local `min' (a nil value)
stack traceback:
   1:  function `Timemess' at line 283 [file `...ramme\PtokaX-0.330.b15.25.dbg\scripts\Top10.lua']
   2:  function `DataArrival' at line 141 [file `...ramme\PtokaX-0.330.b15.25.dbg\scripts\Top10.lua']

VidFamne

I'm not sure about this, but I think it is when you add the script when you still in the hub.
Then your time will be nil.
To solve this is to reconnect to the hub.
Dont have any other solution for it, yet. ;)

xfiles

Hi VidFamne,

GeoIP is a very usefull script.
I?ve been looking for something like that for months.
Now i found it.  :))
Could you just change a tiny thing!?
At the moment the script sends the message in the main. But i would like to get the message in pm.
Is that possible?
I tryed to change this:  SendToNick   into SendPmToNick.
But it seems not to work.

thx a lot m8

VidFamne

Well, the only one who can see the message, is the one who
typed the command.
So it is as private it can be. :)
And for the SendPmToNick I have to declare a global bot,
and thats unnecessary IMHO.

VidFamne

#7
Ehum, I think I missunderstood you. Sorry :)
Thought you mean i would change the script as it is now.
But feel free to change your script  in your way.
You could put this in function Main();

globals().Bot="GeoIpBot"
frmHub:RegBot(Bot)

and change this;
SendToNick(curUser.sName,"**** "..arg.." isn't in our records****")
and this;
SendToNick(curUser.sName,"**** "..arg.." is sitting on localhost")
and this;
SendToNick(curUser.sName,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]")

to this;
SendPmToNick(curUser.sName,Bot,"**** "..arg.." isn't in our records****")
and this;
SendPmToNick(curUser.sName,Bot,"**** "..arg.." is sitting on localhost")
and this;
SendPmToNick(curUser.sName,Bot,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]")

 

Good luck :)


pHaTTy

elo just cleaned a little (was very bored) hope ya donnot mind :-)

--By VidFamne (2004-04-07)
--A first try to do a GeoIp-script 
--With a very fast search algorithm on big tables :)
--Type +Country  and get the Country and CountryCode from an User
--The tGeoIpRange.txt is very big ( about 5.6 MB ) as I have ripped from GeoIPCountryCSV
--Hope its uptodate :)

function Main()
	globals().tGeoIpRange={}
	globals().tGeoIpRangefile="tGeoIpRange.txt"
	dofile(tGeoIpRangefile)
end

function DataArrival(user, data)
	data=strsub(data,1,-2) 
	local s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s*(%S*)" )
	if cmd == "+Country" then 
		if GetItemByName(arg) then
			SendToNick(user.sName,"**** "..arg.." isn't in our records****"); return nil;
		end;
		local compIp = ComputeIP(nick.sIP)
		if compIp == 2130706433 then 
			SendToNick(user.sName,"**** "..arg.." is sitting on localhost");return 1;
		else; local C, CC = tSearchCountry(compIp)
			SendToNick(user.sName,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]")
			return nil;
		end
	end
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----40

function tSearchCountry(num)
	local num = tonumber(num)
	local C = ""; local CC = "";
	local table=tGeoIpRange
	local low = 1; local high = getn(table)

	for i = low, high-low+1 do
		if  table[i][1] <= num and num <= table[i][2]  then 
			local C = table[i][4]; local CC = table[i][3]		  
		elseif table[i][1] > num then; high = floor((high+low)/2)-1
		else low = floor((high+low)/2)+1; end
	end; return C,CC
end

--------------------------VidFamne
Resistance is futile!

VidFamne

#9
No, I dont mind at all.
Everyone should feel free to code in his own coding style.
You have yours, moNo,tezlo has his and its like a fingerprint you cant escape from. :) Lol...
And I have mine, perhaps a little sloppy and recycled, but I do what I can.
Here it is;
--By VidFamne (2004-04-07)
--A first try to do a GeoIp-script 
--With a very fast search algorithm on big tables :)
--Type +Country  and get the Country and CountryCode from an User
--The tGeoIpRange.txt is very big ( about 5.6 MB ) as I have ripped from GeoIPCountryCSV,
--with help from RabidWombat's serialisation function
--Hope its uptodate :)




function Main()
	globals().tGeoIpRange={}
	globals().tGeoIpRangefile="tGeoIpRange.txt"
	dofile(tGeoIpRangefile)
end

function DataArrival(curUser, sData)

      sData=strsub(sData,1,-2) 
      s,e,cmd,arg = strfind( sData, "%b<>%s+(%S+)%s*(%S*)" )
		if (cmd=="+Country") then 
	   	local nick = GetItemByName(arg)
			if nick == nil then
			SendToNick(curUser.sName,"**** "..arg.." isn't in our records****") return 1 end
				local compIp = ComputeIP(nick.sIP)
				if compIp==2130706433 then 
				SendToNick(curUser.sName,"**** "..arg.." is sitting on localhost") return 1 else
				local C, CC = tSearchCountry(compIp)
				SendToNick(curUser.sName,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]") return 1
				end
		end
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----40

function tSearchCountry(num)
  local num = tonumber(num)
  local C = ""
  local CC = ""
  local table=tGeoIpRange
  local low=1
  local high=getn(table)

	for i = low, high-low+1 do
		if  table[i][1] <= num and num <= table[i][2]  then 
		C = table[i][4]
		CC = table[i][3]		  
			elseif table[i][1] > num then high = floor((high+low)/2)-1
			else low = floor((high+low)/2)+1
		end 
	end  
	return C,CC
end

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

yepyepyep4711

wow, this script is using huge amounts of memory :)
the VidFamme version before last had grown to 45 MB.
The last one is already at 30 MB right after starting the script.

VidFamne

Yeah, its a real biggie  :D
I've closed the links, cause I cant host the files anymore :(

yepyepyep4711

#12
hope the hosting problem is only temporary :(

Any chance to see a version were it wouldn't take so much memory? After I day running it has grown from 30MB to 45MB.

How about loading the txt only when needed, and flushing afterwards?

Hades

Knock on my PM!!
This script project i will host it on my private site for free!!
Just let me know if u want!
..........
Can someone add some code to it?
So it shows as welcome message at userenter there is
x useras from xxxx
y users from bala bla bla hope u get it!

VidFamne

Yes, Please do :)
here some tiny change to the binary search algo;
----the Binary Search Algo----40

function tSearchCountry(num)
  local num = tonumber(num)
  local C = ""
  local CC = ""
  local table=tGeoIpRange
  local low=1
  local high=getn(table)

	for i = low, high-low+1 do
		if  table[i][1] <= num and num <= table[i][2]  then 
		C = table[i][4]
		CC = table[i][3] 
		break end		  
			if table[i][1] > num then high = floor((high+low)/2)-1
			else low = floor((high+low)/2)+1
		end 
	end  
	return C,CC
end

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

pHaTTy

QuoteOriginally posted by VidFamne
Yes, Please do :)
here some tiny change to the binary search algo;
----the Binary Search Algo----40

function tSearchCountry(num)
  local num = tonumber(num)
  local C = ""
  local CC = ""
  local table=tGeoIpRange
  local low=1
  local high=getn(table)

	for i = low, high-low+1 do
		if  table[i][1] <= num and num <= table[i][2]  then 
		C = table[i][4]
		CC = table[i][3] 
		break end		  
			if table[i][1] > num then high = floor((high+low)/2)-1
			else low = floor((high+low)/2)+1
		end 
	end  
	return C,CC
end

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

you might wanna keep the c n cc local, they start local and become global

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

function tSearchCountry(num)
	local num = tonumber(num)
	local C = ""; local CC = ""
	local table=tGeoIpRange
	local low = 1; local high=getn(table)

	for i = low, high-low+1 do if  table[i][1] <= num and num <= table[i][2] then 
		local C = table[i][4]; local CC = table[i][3] 
		break; end; if table[i][1] > num then high = floor((high+low)/2)-1
		else low = floor((high+low)/2)+1; end; 
	end; return C,CC
end

--------------------------VidFamne
Resistance is futile!

VidFamne

#16
Yes ofcorse
That Would be an even better improvment.
But sorry to say, its not function properly:(
Thanks anyway Phatty :)

tezlo

no. they dont "become global"
you declare them once as local to the function and they stay that way
and whats with making the code unreadable?

pHaTTy

QuoteOriginally posted by tezlo
no. they dont "become global"
you declare them once as local to the function and they stay that way
and whats with making the code unreadable?

well actually ur wrong i done some testing and they do become global after accidently finding that when writing a script, globally calling a local varaiblethat was localaised in a function, and its not unreadable, i just cant use it when the lines are all the way down the page, sop its a habit to keep everything together

similar locals go together and as for ifs, like to keep em close to the old end if they have sep end, less cr*pcode to look at, and easier for me to read tbh, so if ya cant read that u need ot start practicing

n fact when i run hub later, i will probby make a script to show ya, but tbh im pretty pizzed off atm so ima go...
:)
Resistance is futile!

pHaTTy

QuoteOriginally posted by VidFamne
Yes ofcorse
That Would be an even better improvment.
But sorry to say, its not function properly:(
Thanks anyway Phatty :)

i will run test hub later n see what mistake i made heh
Resistance is futile!

tezlo

#20
right..
function test()
	local five
	five = 5
end

test()
if five == nil then
	SendToAll(">> see?!")
end

VidFamne

#21
That was good to hear that it stays local :)
Another thing I was thinking of;
the limit and steps are evaluated only once, before the loop starts, in a for loop, so this must be more adequate? ;
----the Binary Search Algo----40

function tSearchCountry(num)
  local num = tonumber(num)
  local C = ""
  local CC = ""
  local table=tGeoIpRange
  local low=1
  local high=getn(table)

	for i = low, getn(table) do
		if  table[i][1] <= num and num <= table[i][2]  then 
		C = table[i][4]
		CC = table[i][3] 
		break end		  
			if table[i][1] > num then high = floor((high+low)/2)-1
			else low = floor((high+low)/2)+1
			end 
	end  
	return C,CC
end

--------------------------VidFamne
**Edit; changed it again :)

VidFamne

Tiny change to the binary search algo.
Have removed the local table, cause there is alredy declared an global table, and that's IMHO, enough. :D
Dont know if this gain any performance.
But on my little test hub, I cant see that G.C. rise a singel byte :)
--By VidFamne (2004-04-07)
--A first try to do a GeoIp-script 
--With a very fast search algorithm on big tables :)
--Type +Country  and get the Country and CountryCode from an User
--The tGeoIpRange.txt is very big ( about 5.6 MB ) as I have ripped from GeoIPCountryCSV,
--with help from RabidWombat's serialisation function
--Hope its uptodate :)
--Tiny change in the B.S.Algo :) (2004-04-18)




function Main()
	globals().tGeoIpRange={}
	globals().tGeoIpRangefile="tGeoIpRange.txt"
	dofile(tGeoIpRangefile)
end

function DataArrival(curUser, sData)

      sData=strsub(sData,1,-2) 
      s,e,cmd,arg = strfind( sData, "%b<>%s+(%S+)%s*(%S*)" )
		if (cmd=="+Country") then 
	   	local nick = GetItemByName(arg)
			if nick == nil then
			SendToNick(curUser.sName,"**** "..arg.." isn't in our records****") return 1 
			end
			local compIp = ComputeIP(nick.sIP)
				if compIp==2130706433 then 
				SendToNick(curUser.sName,"**** "..arg.." is sitting on localhost") return 1 
				else
				local C, CC = tSearchCountry(compIp)
				SendToNick(curUser.sName,"**** "..arg.." is from "..C.." and have CountryCode ["..CC.."]") 
				return 1 
				end
		end

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----40

function tSearchCountry(num)
  local num = tonumber(num)
  local C = ""
  local CC = ""
  local low=1
  local high=getn(tGeoIpRange)

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

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

Xico

#23
I'm very new to this world, so just a question: where can I find the file "tGeoIpRange.txt" or information to generate it?

This is a very useful script, and a very good shearch rutine.

Thanks

xfiles

#24
Oi Xico,

essa file posso-te mandar se quiseres. Manda-me uma pm ou e-mail.
Esse script ? bom para veres de onde v?m os users e d?-te tamb?m o c?digo do pa?s.
Se tens um Hub aonde o pessoal tem que por o c?digo do pa?s no nick, esse script pode-te ajudar.

Cumprimentos :)

SMF spam blocked by CleanTalk