PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: -SkA- on 12 October, 2006, 12:48:14

Title: Script for unban IPs in a range
Post by: -SkA- on 12 October, 2006, 12:48:14
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
Title: Re: Script for unban IPs in a range
Post by: NightLitch on 12 October, 2006, 13:05:17
Allready on it mate  ;)
Title: Re: Script for unban IPs in a range
Post by: NightLitch on 12 October, 2006, 13:16:37
Code (lua) Select

--// !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
Title: Re: Script for unban IPs in a range
Post by: -SkA- on 27 May, 2007, 09:09:16
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.
Title: Re: Script for unban IPs in a range
Post by: bastya_elvtars on 27 May, 2007, 09:49:30
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
Title: Re: Script for unban IPs in a range
Post by: -SkA- on 27 May, 2007, 20:35:48
iprangeunban.lua:34: attempt to call field 'mod' (a nil value)
Title: Re: Script for unban IPs in a range
Post by: Psycho_Chihuahua on 27 May, 2007, 20:48:17
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)))
Title: Re: Script for unban IPs in a range
Post by: -SkA- on 27 May, 2007, 21:13:28
Ok, now no errors, but it doesn't unban IPs....strange...
Title: Re: Script for unban IPs in a range
Post by: bastya_elvtars on 27 May, 2007, 22:12:20
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
Title: Re: Script for unban IPs in a range
Post by: -SkA- on 28 May, 2007, 11:00:07
[10:51:02] <????? ????> Unbanned: 0 IP(s)
[10:51:38] <????? ????> Unbanned: 0 IP(s)

:(
Title: Re: Script for unban IPs in a range
Post by: NightLitch on 28 May, 2007, 12:46:19

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