IP Bot - Page 2
 

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

IP Bot

Started by SilvaO, 21 May, 2005, 18:09:49

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zero-cool

Hi,

This on converts CIDR to Range IP, decimal and binary. Sort table by Isp.
Use on CIDR file:
xxx.xxx.xxx.xxx/xx # Isp

--### Variables ----------------------------------------------------------------------------------------------------
fFinal="IPs.txt" -- Final file with Range IP
fDecimal = "IPsDec.txt" -- Final file with decimal IP
fBinario = "IPsBin.txt" -- Final file with binary IP

file="ipranges.txt" -- File with CIDR ranges
--[[
	Must be:
	xxx.xxx.xxx.xxx/xx # ISP
	
	Please, don't forget your ISP. Table will be sort by ISP
]]--

tRanges={}
tRangesDEC={}
tRangesBIN={}

--### Functions ------------------------------------------------------------------------------------------------------

function IpToDec(op1, op2, op3, op4, CIDR)
	decstart = op1 * (256^3) + op2 * (256^2) + op3 * 256 + op4
  	decend = decstart + (2^(32 - CIDR)) - 1
end

function DecToIp(decend)
	ipad1 = math.floor(decend / (256^3))
	ipad2 = math.floor((decend - (ipad1 * (256^3)))/(256^2))
	ipad3 = math.floor((decend - (ipad1*(256^3) + ipad2*(256^2)))/256)
	ipad4 = math.floor((decend - (ipad1*(256^3) + ipad2*(256^2) + ipad3 * 256)))
end

function DecToBin(decstart)
	d = decstart
	local bin_s = ""
	while (d > 1) do
		a = math.floor(d/2)
		b = (d/2)-a
		if ( b > 0) then
			bin_s = "1"..bin_s
		else
			bin_s = "0"..bin_s
		end
		d = a
	end
	bin_s = "1"..bin_s
	return bin_s
end

function SaveToFile(file, tablename, tablename1)
	local handle = io.open(file,"w+")
	handle:write(tablename1.." = {\n")
	for Isps in tablename do
		local Isps1 = (type(Isps) == "string") and string.format("%q",Isps) or tostring(Isps);
		handle:write("\t["..Isps1.."] = {\n")
		for First, Last in tablename[Isps] do
			handle:write("\t\t["..First.."] = "..Last..",\n")
		end
		handle:write("\t},\n")
	end
	handle:write("}")
	handle:flush()
	handle:close()
end
	
--### Read you IP-CIDR file ---------------------------------------------------------------------------------
for line in io.lines(file) do 
	_,_,op1,op2,op3,op4,CIDR,Isp=string.find(line,"(%d+).(%d+).(%d+).(%d+)/(%d+)%s+#%s+(.+)")

  	IpToDec(op1, op2, op3, op4, CIDR)
	DecToIp(decend)
	bins = DecToBin(decstart)
	binf = DecToBin(decend)

	if tRanges[Isp] == nil then
		tRanges[Isp] = {}
		tRanges[Isp][op1.."."..op2.."."..op3.."."..op4] = ipad1.."."..ipad2.."."..ipad3.."."..ipad4
	else		
		tRanges[Isp][op1.."."..op2.."."..op3.."."..op4] = ipad1.."."..ipad2.."."..ipad3.."."..ipad4
	end
	if tRangesDEC[Isp] == nil then
		tRangesDEC[Isp] = {}
		tRangesDEC[Isp][decstart] = decend
	else		
		tRangesDEC[Isp][decstart] = decend
	end
	if tRangesBIN[Isp] == nil then
		tRangesBIN[Isp] = {}
		tRangesBIN[Isp][bins] = binf
	else		
		tRangesBIN[Isp][bins] = binf
	end
end

--### Save Files -------------------------------------------------------------------------------------------
if loadfile(fFinal) then dofile(fFinal) end
SaveToFile(fFinal , tRanges , "tRanges") 

if loadfile(fDecimal) then dofile(fDecimal) end
SaveToFile(fDecimal, tRangesDEC, "tRangesDEC") 

if loadfile(fBinario) then dofile(fBinario) end
SaveToFile(fBinario, tRangesBIN, "tRangesBIN")


Regards,

GeceBekcisi

zero-cool you'd check this thread since your code has the same issue
Do you need an advanced user handling script? Download UserBekcisi today (Latest Edit)
Features: User + ISP + GeoIP database, user info + share checking and many more...

zero-cool

Quote from: GeceBekcisi on 09 June, 2006, 12:13:21
zero-cool you'd check this thread since your code has the same issue
Thanks !  ;) ;)

Alexinno

GeceBekcisi your script doesn't have rightclick suport ? :(

GeceBekcisi

Well, it's not an end-user code, it's a part of one of my bot's and posted here for development purposes.
Do you need an advanced user handling script? Download UserBekcisi today (Latest Edit)
Features: User + ISP + GeoIP database, user info + share checking and many more...

SMF spam blocked by CleanTalk