Script for unban IPs in a range
 

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

Script for unban IPs in a range

Started by -SkA-, 12 October, 2006, 12:48:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

-SkA-

Hello scripters  :)

I would like to know if you can make a script that unban IPs founded in a specified range of IPs.

Example:

!iprangeunban 213.140.0.1-213.140.10.254    it searches IPs in that range and unbans IPs founded.


Thanks  ;D
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

NightLitch

//NL

NightLitch

#2
Code: lua
--// !iprangeunban 213.140.0.1 - 213.140.10.254
--// It searches IPs in that range and unbans IPs founded.
--// Request by -SkA-
--// Created by NightLitch (2006)

ChatArrival = function(user,data)
	local _,_,cmd,arg = string.find(data,"%b<>%s(%S+)%s*(.*)%|")
	if cmd and cmd == "!iprangeunban" and user.bOperator then
		local ok,_,from,to = string.find(arg, "(%d+%.%d+%.%d+%.%d+)%s%-%s(%d+%.%d+%.%d+%.%d+)")
		if ok then
			from = IPToDec(from); to = IPToDec(to);
			local c = 0
			for i = 0, (to-from) do
				local ip = DecToIP(from+i)
				if Unban(ip) then c = c + 1 end
			end
			user:SendData(frmHub:GetHubBotName(),"Unbanned: "..c.." IP(s)")
		else
			user:SendData(frmHub:GetHubBotName(), "*** Syntax: !iprangeunban <from> - <to>")
		end
		return 1
	end
end

IPToDec = function(ip)
	local _,_,a,b,c,d = string.find(ip, "(%d+).(%d+).(%d+).(%d+)")
	return a*16777216 + b*65536 + c*256 + d
end

DecToIP = function(ip)
	if math.mod then
		local temp1 = math.mod(ip,16777216)
		local temp2 = math.mod(temp1,65536)
		return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.mod(temp2,256)))
	else
		local temp1 = math.fmod(ip,16777216)
		local temp2 = math.fmod(temp1,65536)
		return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.fmod(temp2,256)))
	end
end
//NL

-SkA-

Thank you mate, nice job.  ;D
Hello,

from version 0.3.6.0 , the above script stop working  :o

If I try to unban IPs (presents in banlist) in a specified range then It always answers:

Unbanned: 0 IP(s)

Could someone fix it? Thanks.
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

bastya_elvtars

try this (untested):

--// !iprangeunban 213.140.0.1 - 213.140.10.254
--// It searches IPs in that range and unbans IPs founded.
--// Request by -SkA-
--// Created by NightLitch (2006)
 
ChatArrival = function(user,data)
	local _,_,cmd,arg = string.find(data,"%b<>%s(%S+)%s*(.*)%|")
	if cmd and cmd == "!iprangeunban" and user.bOperator then
		local ok,_,from,to = string.find(arg, "(%d+%.%d+%.%d+%.%d+)%s%-%s(%d+%.%d+%.%d+%.%d+)")
		if ok then
			from = IPToDec(from); to = IPToDec(to);
			local c = 0
			for i = 0, (to-from) do
				local ip = DecToIP(from+i)
				if Unban(ip) then c = c + 1 end
			end
			user:SendData(frmHub:GetHubBotName(),"Unbanned: "..c.." IP(s)")
		else
			user:SendData(frmHub:GetHubBotName(), "*** Syntax: !iprangeunban <from> - <to>")
		end
		return 1
	end
end
 
IPToDec = function(ip)
	local _,_,a,b,c,d = string.find(ip, "(%d+).(%d+).(%d+).(%d+)")
	return a*16777216 + b*65536 + c*256 + d
end
 
DecToIP = function(ip)
	if math.modf then
		local temp1 = math.modf(ip,16777216)
		local temp2 = math.modf(temp1,65536)
		return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.mod(temp2,256)))
	else
		local temp1 = math.fmod(ip,16777216)
		local temp2 = math.fmod(temp1,65536)
		return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.fmod(temp2,256)))
	end
end
Everything could have been anything else and it would have just as much meaning.

-SkA-

iprangeunban.lua:34: attempt to call field 'mod' (a nil value)
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

Psycho_Chihuahua

try changing line 34 from
return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.mod(temp2,256)))


to

return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.modf(temp2,256)))
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

-SkA-

Ok, now no errors, but it doesn't unban IPs....strange...
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

bastya_elvtars

Untested again:

--// !iprangeunban 213.140.0.1 - 213.140.10.254
--// It searches IPs in that range and unbans IPs founded.
--// Request by -SkA-
--// Created by NightLitch (2006)

--// Made strict Lua 5.1 and replaced some functions by bastya_elvtars
 
ChatArrival = function(user,data)
	local cmd,arg = string.match(data,"%b<>%s(%S+)%s*(.*)%|")
	if cmd and cmd == "!iprangeunban" and user.bOperator then
		local from,to = string.match(arg, "(%d+%.%d+%.%d+%.%d+)%s%-%s(%d+%.%d+%.%d+%.%d+)")
		if from then
			from = IPToDec(from); to = IPToDec(to);
			local c = 0
			for i = 0, (to-from) do
				local ip = DecToIP(from+i)
				if Unban(ip) then c = c + 1 end
			end
			user:SendData(frmHub:GetHubBotName(),"Unbanned: "..c.." IP(s)")
		else
			user:SendData(frmHub:GetHubBotName(), "*** Syntax: !iprangeunban <from> - <to>")
		end
		return 1
	end
end
 
function IPToDec(ip)
  local err
  local c=256^3
	local decip=0
  for b in string.gmatch(ip,"(%d+)") do
    local piece=tonumber(b)
    if not piece or piece > 255 then
      err=true
      break
    else
      decip=decip+(piece*c)
      c=c/256
    end
  end
  if not err then
    return decip
  end
end

function DecToIP(ip)
  local tmp
  local pt1,pt2,pt3,pt4
  pt1=math.modf((ip)/256^3)
  tmp=math.fmod((ip),256^3)
  pt2=math.modf((tmp)/256^2)
  tmp=math.fmod(tmp,256^2)
  pt3=math.modf((tmp)/256)
  pt4=math.fmod(tmp,256)
  return pt1.."."..pt2.."."..pt3.."."..pt4
end
Everything could have been anything else and it would have just as much meaning.

-SkA-

[10:51:02] <????? ????> Unbanned: 0 IP(s)
[10:51:38] <????? ????> Unbanned: 0 IP(s)

:(
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

NightLitch

#10
--//---------------------------------------------------------------------------
--// Rewritten for PtokaX Lua 5.1.x by NightLitch (2007)
--//---------------------------------------------------------------------------
--// Usage:
--// !iprangeunban 213.140.0.1 - 213.140.10.254
--// !iprunban 213.140.0.1 - 213.140.10.254
--//---------------------------------------------------------------------------

ChatArrival = function(user,data)
	local cmd,arg = data:match("%b<>%s(%S+)%s*(.*)%|")
	if cmd and cmd == "!iprangeunban" and user.bOperator then
		return UnBanRange(user,arg)
	elseif cmd and cmd == "!iprunban" and user.bOperator then
		return UnBanRange(user,arg)
	elseif cmd and cmd == "!uban" and user.bOperator then
		if arg ~= "" then
			if Unban(arg) then
				user:SendData(frmHub:GetHubBotName(),"Unbanned: "..arg)
			else
				user:SendData(frmHub:GetHubBotName(),"Couldn't unban: "..arg)
			end
		else
			user:SendData(frmHub:GetHubBotName(),"Syntax: !uban <ip>")
		end
	end
end

UnBanRange = function(user,arg)
	local from,to = arg:match("(%d+%.%d+%.%d+%.%d+)%s%-%s(%d+%.%d+%.%d+%.%d+)")
	if from then
		from = IPToDec(from); to = IPToDec(to);
		local c = 0
		local ip = -1
		for i = 0, (to-from) do
			ip = DecToIP(from+i)
			if GetBannedItemName(ip) then
				c = c + 1 
				Unban(ip)
			end
		end
		user:SendData(frmHub:GetHubBotName(),"Unbanned: "..c.." IP(s)")
	else
		user:SendData(frmHub:GetHubBotName(), "*** Syntax: !iprangeunban <from> - <to>")
	end
	return 1
end

IPToDec = function(ip)
	local a,b,c,d = ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")
	return a*16777216 + b*65536 + c*256 + d
end
 
DecToIP = function(ip)
	local temp1 = math.fmod(ip,16777216)
	local temp2 = math.fmod(temp1,65536)
	return (math.floor(ip/16777216).."."..math.floor(temp1/65536).."."..math.floor(temp2/256).."."..math.floor(math.fmod(temp2,256)))
end

//NL

SMF spam blocked by CleanTalk