PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 08 February, 2004, 23:24:43

Title: How to loop function to get ranges til MAX set! HELP!
Post by: NightLitch on 08 February, 2004, 23:24:43
hey guys!

I wanna loop or solve so the function start at 129 to 255

and between every number the ranges found saved into a file.

hope you get me otherwise I explain myself more later.

--* * * Range Resolver * * *
-- By: NightLitch 2004

Temp = {}

hFile = "RANGES.DAT"

function checkwhois(ip)
local line, range, descr = ""
local socket, err = connect("whois.ripe.net", 43)
if not err then
socket:timeout(2)
err = socket:send(ip..strchar(13, 10))
while not err do
local s, e, key, value = strfind(line, "^(%l+)%:%s*(.*)$")
if s then
if key == "inetnum" then range = value
elseif key == "netname" then descr = value break end
end
line, err = socket:receive("*l")
end
socket:close()
end
return range, descr
end

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

function NewUserConnected(user)
Range = {
["81.8.129.0"] = "81.8.255.255"
}
-- local count = 0


-----  PROBLEM HERE TO:

for ar,br in Range do
local _,_,a,b,c,d = strfind(ar, "(%d*).(%d*).(%d*).(%d*)")
if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
count = c +1

vRange = a.."."..b.."."..count.."."..0

local range, descr = checkwhois(vRange)
if descr then
SendToAll("Range: "..range.." Descr: "..descr)
Temp[range] = descr
saveTableToFile(hFile, Temp)
if c == 255 then
SendToAll("Ranges Captured")
return 1
end
else
SendToAll("N/A")
end
end
end

---------- HERE!!!!

end


function saveTableToFile(file, table)
if type(table) == "table" then
local aString = pickle(table)
if aString then
writeto(file)
write(aString)
writeto()
else
error("Unable to save the table")
end
end
end

function loadTableFromFile(file)
readfrom(file)
local aString = read("*all")
readfrom()
if aString ~= nil then
return unpickle(aString)
else
return {}
end
end

----------------------------------------------
-- Pickle.lua
-- An table serialization utility for lua
-- Steve Dekorte, http://www.dekorte.com, Apr 2000
-- Freeware
----------------------------------------------

function pickle(t)
return Pickle:clone():pickle_(t)
end

Pickle = {
clone = function (t) local nt={}; for i, v in t do nt[i]=v end return nt end
}

function Pickle:pickle_(root)
if type(root) ~= "table" then
error("can only pickle tables, not ".. type(root).."s")
end
self._tableToRef = {}
self._refToTable = {}
local savecount = 0
self:ref_(root)
local s = ""

while getn(self._refToTable) > savecount do
savecount = savecount + 1
local t = self._refToTable[savecount]
s = s.."{\n"
for i, v in t do
if self:value_(v) then
s = format("%s[%s]=%s,\n", s, self:value_(i), self:value_(v))
else
end
end
s = s.."},\n"
end

return format("{%s}", s)
end

function Pickle:value_(v)
local vtype = type(v)
if vtype == "string" then return format("%q", v)
elseif vtype == "number" then return v
elseif vtype == "table" then return "{"..self:ref_(v).."}"
else --error("pickle a "..type(v).." is not supported")
end
end

function Pickle:ref_(t)
local ref = self._tableToRef[t]
if not ref then
if t == self then error("can't pickle the pickle class") end
tinsert(self._refToTable, t)
ref = getn(self._refToTable)
self._tableToRef[t] = ref
end
return ref
end

----------------------------------------------
-- unpickle
----------------------------------------------

function unpickle(s)
if type(s) ~= "string" then
error("can't unpickle a "..type(s)..", only strings")
end
local tables = dostring("return "..s)
if type(tables) ~= "table" then
return {}
end
for tnum = 1, getn(tables) do
local t = tables[tnum]
local tcopy = {}; for i, v in t do tcopy[i] = v end
for i, v in tcopy do
local ni, nv
if type(i) == "table" then ni = tables[i[1]] else ni = i end
if type(v) == "table" then nv = tables[v[1]] else nv = v end
t[ni] = nv
end
end
return tables[1]
end

really want this help plz!

/NL
Title:
Post by: NightLitch on 09 February, 2004, 00:55:47
Hope to get some help... plz.
Title:
Post by: VidFamne on 09 February, 2004, 04:41:09
Dont know if I get it right, but if you put this;
if c >= 129 and c<=255 then in there some place, to get the right range.
Just a wild guess:))
Title:
Post by: c h i l l a on 09 February, 2004, 10:00:05
just some ways,

for i = 129,255 do

func here

end



i = 129
while i <= 255 do

func here

i = i+1

end

and some other ways.

but if you really want to read out all ranges with tezlos whois, then dunno you'll need a lot of time. And the socket will stop the hub.
Title:
Post by: NightLitch on 09 February, 2004, 11:21:30
Yeah I know that, But it will run on my hub with only me,
Our hub need to find out what every range has for netname to get right ISP. if there is another faster way than this to go trough MANY ranges tell. me I found this the smartest.

Just give me the hints or help I need to create it to get the names from every C-net 0.0.here.0 or better maybe
start from the back 0.0.0.here and working up to a stop.

Just help me. It fills no function in a populated hub.

This is just a script to help us others to do some things faster.

Thx for the help... / NL
Title:
Post by: c h i l l a on 09 February, 2004, 11:25:39
well hint is given ;)

and there are c-nets, listed on the net.
Title:
Post by: NightLitch on 09 February, 2004, 13:38:15
Yes I know that, but it will take an enormus time to locate all our ranges.

So I find this way simplier. We have our ranges but we need the netnames so we know who we are dealing with.