PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Snooze on 25 March, 2004, 15:15:42

Title: [Request]Network Status check
Post by: Snooze on 25 March, 2004, 15:15:42
hey guys,

I once saw a small script that would check if a network hub were online, and if not it would send a PM to all Ops, Master or what ever .. The thing is that im not sure it were for ptokax ...

I've searched this forum with no luck :( So if anyone know this script, please let me know ..

Should you think that its a kewl idea and have a nice way to script this, please do so

**Snooze
-Still searching..
Title:
Post by: kepp on 25 March, 2004, 15:40:22
mmm... hmmm

Ok, It's not a good a idea to use this as it will freeze your hub for a few seconds...
But as i am new to sockets in lua i couln't resist!!


sBot = "Test"
Hub_Adress = "dware.com"
HubPort = "411"

function DataArrival(user, data)
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd=="+disp" then
s = connect(Hub_Adress,HubPort)
if s == nil then
user:SendData(sBot,"Hub is Offline")
else
user:SendData(sBot,"hub is Online")
s:close() return 1
end
end
end

Don't say i didn't warn you... It's on your own responsibility!
Title:
Post by: Snooze on 25 March, 2004, 15:55:42
Thanks kepp :))

Though as reading your warning i have to ask ... Is there a better way to do this ?


**Snooze
Title:
Post by: kepp on 25 March, 2004, 16:16:56
i don't think so, unless it's in another langugae, such as VB, C++ or something.
hmm, Well, maybe...

If you use a client which support LUA scripts such as BCDC, then you can ask in the Client section of this forum, im sure they can help you..
Title:
Post by: ??????Hawk?????? on 25 March, 2004, 16:25:51
hmmm  very interesting..

this script done client side would be great..
activated by pm command

if you really want to freeze your hub up try this....



sBot = "Test"
Hub_Adress = {
"hub1.no-ip.org",
"hub2.dynu.com",
"hub3.no-ip.org",
"hub4.servemp3.com",
"hub5.no-ip.org",
"hub6.servemp3.com",
"hub7.no-ip.com",

 }
HubPort = "411"

function DataArrival(user, data)
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd=="+netstat" then
for h=1,getn(Hub_Adress) do
a = connect(Hub_Adress[h],HubPort)
if a == nil then
user:SendData(sBot,Hub_Adress[h].."   Hub is Offline")
else
user:SendData(sBot,Hub_Adress[h].."   hub is Online  ")
a:close()
end
end
end
end

Title:
Post by: Snooze on 25 March, 2004, 17:13:38
I jsut tested it with 7 of our network hubs

12 secs of silence :P

as this will only be running in an Ops Hub a few secs of "stall" wont do no harm ... but 10+ secs wont work.
Any chance of setting this on a timer so it will do the seach with 5 min interval .. as in check hub1 then wait 5 min, then seach hub2 etc etc ?


**Snooze
Title:
Post by: kepp on 25 March, 2004, 17:37:16
sBot = "Test"

Hub_Adress = {
"hub1.no-ip.org",
"hub2.dynu.com",
"hub3.no-ip.org",
"hub4.servemp3.com",
"hub5.no-ip.org",
"hub6.servemp3.com",
"hub7.no-ip.com",

 }
HubPort = "411"

sSearch = 0

function Main()
SetTimer(50000)
StartTimer()
end

function OnTimer()
if sSearch == 0 then
Connect(rawget(1),HubPort)
sSearch = sSearch + 1

elseif sSearch == 1 then
Connect(rawget(2),HubPort)
sSearch = sSearch + 1

elseif sSearch == 2 then
Connect(rawget(3),HubPort)
sSearch = sSearch + 1

elseif sSearch == 3 then
Connect(rawget(4),HubPort)
sSearch = sSearch + 1

elseif sSearch == 4 then
Connect(rawget(5),HubPort)
sSearch = sSearch + 1

elseif sSearch == 5 then
Connect(rawget(6),HubPort)
sSearch = sSearch + 1

elseif sSearch == 6 then
Connect(rawget(7),HubPort)
sSearch = sSearch + 1
end
end


function Connect(IP,PORT)

a = connect(IP,PORT)
if a == nil then
SendToOps(sBot,IP.." Is Currently Offline.")
else
SendToOps(sBot,IP.." Is Currently Online.")
a:close()
end
end
Title:
Post by: Snooze on 25 March, 2004, 17:50:28
yeps ..something like that :)) - though "Syntax Error: bad argument #1 to `rawget' (table expected, got number)" :(

Help me out, please :)


*Snooze
Title:
Post by: kepp on 25 March, 2004, 17:59:57

sBot = "Test"

Hub_Adress = {
"hub1.no-ip.org",
"hub2.dynu.com",
"hub3.no-ip.org",
"hub4.servemp3.com",
"hub5.no-ip.org",
"hub6.servemp3.com",
"hub7.no-ip.com",

 }
HubPort = "411"

sSearch = 0

function Main()
SetTimer(50000)
StartTimer()
end

function OnTimer()
if sSearch == 0 then
Connect(Hub_Adress[1],HubPort)
sSearch = sSearch + 1

elseif sSearch == 1 then
Connect(Hub_Adress[2],HubPort)
sSearch = sSearch + 1

elseif sSearch == 2 then
Connect(Hub_Adress[3],HubPort)
sSearch = sSearch + 1

elseif sSearch == 3 then
Connect(Hub_Adress[4],HubPort)
sSearch = sSearch + 1

elseif sSearch == 4 then
Connect(Hub_Adress[5],HubPort)
sSearch = sSearch + 1

elseif sSearch == 5 then
Connect(Hub_Adress[6],HubPort)
sSearch = sSearch + 1

elseif sSearch == 6 then
Connect(Hub_Adress[7],HubPort)
sSearch = sSearch + 1
end
end


function Connect(IP,PORT)

a = connect(IP,PORT)
if a == nil then
SendToOps(sBot,IP.." Is Currently Offline.")
else
SendToOps(sBot,IP.." Is Currently Online.")
a:close()
end
end

And this?
Title:
Post by: Snooze on 25 March, 2004, 18:17:03
Works perfectly - thanks m8 :)))



**Snooze
- still learning..
Title:
Post by: ??????Hawk?????? on 25 March, 2004, 18:23:00
try this  

+neton  -- turns it on
+netoff  -- turns it off





sBot = "Network-online-check-  "
Hub_Adress = {
"hub1.no-ip.org",
"hub2.dynu.com",
"hub3.no-ip.org",
"hub4.servemp3.com",
"hub5.no-ip.org",
"hub6.servemp3.com",
"hub7.no-ip.com",

 }
HubPort = "411"
curenthub = 1
mins = 1
function Main()
hubcount = getn(Hub_Adress)
SetTimer(1000 * 60 * mins)

end

function DataArrival(user, data)
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd=="+neton" then
SendToOps(sBot," netstats enabled ")
StartTimer()
elseif cmd=="+netoff" then
SendToOps(sBot," netstats disabled ")
 StopTimer()
end
end

function OnTimer()
displayhub(curenthub)
if curenthub == hubcount then
curenthub = 0
end
curenthub = curenthub + 1
end


function displayhub(curenthub)
a = connect(Hub_Adress[curenthub],HubPort)
if a == nil then
SendToOps(sBot,Hub_Adress[curenthub].."   Hub is Offline")
else
SendToOps(sBot,Hub_Adress[curenthub].."   hub is Online  ")
a:close()
end
end

Title:
Post by: kepp on 25 March, 2004, 18:48:58
Yep indeed, i thought to fast :) lol
Title:
Post by: Snooze on 25 March, 2004, 18:54:04
All it needs to be perfect is a port setting as not all hubs is running on port 411 ;)

Thanks goes to both of you for your help :))


**Snooze
Title:
Post by: Typhoon on 25 March, 2004, 19:12:07
heres one by [ES]latinmusic


-------------------------------------------------------------------------------------------------------
-- ![NetStatus]!? script - v1.1 - Created by [ES]latinmusic __/04/2003
-- Powered by ARACNIDOS.NET?  -  No Rights Reserved
-- Thanks go out to all people from LUA Board, old and new one
-- Some of the original code was developed by some one i don't remember
-- If you were envolving in this code, tell me and you will be added into credits
-- Multilanguage Version (Spanish & English)
--  ***************************************************************************
*************************
-- This Script: Show if the hubs listed inside the array are online or offline in real time
-- Could be usefull if you are running a net of hubs or you wanna see if your friends hubs are online
-- Command for this script '-netstat'
-- To set up this script working under your needs, read the help inside the code
-- Enjoy...
-------------------------------------------------------------------------------------------------------
------- Main function -------
function Main()
botName="![NetStatus]!?" --//Help: Name of the bot.
--frmHub:RegBot(botName) --//Help: This line is not requiered, is only a comment for Ptacek.
CoolLine=strrep("-",250) --//Help: This line could be nosense for the upcoming release in test of PtokaX since code about PMs have been change, in this case remove it from the script.
waitmessage=strrep(" ...WAIT...ESPERE... ",6) --//Help: Same of above. If you delete those lines, also you have to delete the variables related from the script in messages part
--------- HubsArrayHelp --------
-------Formating the array------
-- HubAddress = {
-- ["Hub{0} Name Of The Hub] = Change 'Name Of The Hub' to the real hub name
-- address= "Address Of The Hub", Change 'Address Of The Hub' to the real hub address
-- port = Port Of The Current Hub, Change 'Port Of The Current Hub' to the real hub port
-- }, For examples take a look into the following lines
--------- HubsArrayHelp --------
HubAddress = {
["Hub{0} ?ARACNIDOS?-=MAIN SERVER=-?"] = { --//Help: Put here the real name of the HUB
address= "aracnidos.no-ip.com", --//Help: Put here the real address  of the HUB
port = 411, --//Help: Put here the real port of the HUB
},
["Hub{1} ?ARACNIDOS#1?-=SUPPORT SERVER=-?"] = { --//Help: Put here the real name of the HUB
address= "aracnidos1.no-ip.com", --//Help: Put here the real address of the HUB
port = 411, --//Help: Put here the real port of the HUB
},
["Hub{2} ?ARACNIDOS#2?-=SUPPORT SERVER=-?"] = { --//Help: Put here the real name of the HUB
address= "aracnidos2.no-ip.com", --//Help: Put here the real address of the HUB
port = 411, --//Help: Put here the real port of the HUB
},
["Hub{3} ?ARACNIDOS#3?-=SUPPORT SERVER=-?"] = { --//Help: Put here the real name of the HUB
address= "aracnidos3.no-ip.com", --//Help: Put here the real address of the HUB
port = 411, --//Help: Put here the real port of the HUB
},
["Hub{4} ?ARACNIDOS#4?-=SUPPORT SERVER=-?"] = { --//Help: Put here the real name of the HUB
address= "aracnidos4.no-ip.com", --//Help: Put here the real address of the HUB
port = 411, --//Help: Put here the real port of the HUB
}
}
end
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
-- get the msg only using regular expression
s,e,message = strfind(data, "%b<> (.*)")
--remove pipe
message = strsub(message,1,strlen(message)-1)
s,e,cmd=strfind(message,"(%S+)")
if (cmd=="-netstat")then
for i,v in HubAddress do
user:SendPM(botName,"\r\nRequesting Net Information for "..i.."\r\nPlease "..waitmessage.."\r\n")
local socket, err = connect(v["address"], v["port"])
if not err then socket:close()
status = "<----------------------------> {{**ONLINE**}}"
else
status = "<----------------------------> {{**OFFLINE**}}   :-("
end
user:SendPM(botName,"\r\n"..CoolLine.."\r\n"..i.."\r\n<> Address: "..v["address"].."\r\n<> Port:"..v["port"].."\r\n<> Status: "..status.."\r\n"..CoolLine.."\r\n")
end
user:SendPM(botName,"The request for Online/Offline Hubs have been completed [El chequeo de HUBs Conectados/Desconectados ha concluido]\r\n")
end
end
end
--function OnExit() --//Help: This line is not requiered, is only a comment for Ptacek.
-- frmHub:UnregBot(botName) --//Help: This line is not requiered, is only a comment for Ptacek.
--end --//Help: This line is not requiered, is only a comment for Ptacek.


Title:
Post by: kepp on 25 March, 2004, 19:30:33
Well well well, ^^ there you have one :)
Title:
Post by: ??????Hawk?????? on 25 March, 2004, 19:41:51

sBot = "Network-online-check-  "
Hub_Adress = {
"hub1.no-ip.org",
"411",
"hub2.no-ip.org",
"456",
"hub3.no-ip.org",
"485",
"hub4.no-ip.com",
"645",
"hub5.no-ip.com",
"645",
"hub6.no-ip.com",
"645",
"hub7.no-ip.com",
"412",

 }
HubPort = "411"
curenthub = 1
curentport = 2
mins = 1
function Main()
hubcount = getn(Hub_Adress)
SetTimer(1000 * 60 * mins)

end

function DataArrival(user, data)
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd=="+neton" then
SendToOps(sBot," netstats enabled ")
StartTimer()
elseif cmd=="+netoff" then
SendToOps(sBot," netstats disabled ")
 StopTimer()
end
end

function OnTimer()
if curentport == hubcount + 2 then
curenthub = 1
curentport = 2
end
displayhub(curenthub,curentport)
curenthub = curenthub + 2
curentport = curenthub + 1
end

function displayhub(curenthub,curentport)
a = connect(Hub_Adress[curenthub],Hub_Adress[curentport])
if a == nil then
SendToOps(sBot,Hub_Adress[curenthub]..":"..Hub_Adress[curentport].."   Hub is Offline")
else
SendToOps(sBot,Hub_Adress[curenthub]..":"..Hub_Adress[curentport].."   hub is Online  ")
a:close()
end
end


Title:
Post by: Snooze on 03 May, 2004, 23:58:13
This script is still working perfectly, but i had a good idea ...

This script is now running in 6 hubs checking on all hubs and making sure that the redirect chain isnt broken by sending a msg to ops if an hub is down.
My idea is that the script should auto change the redirect if the next hub in line is down.

The redirect chain goes as the same way as the address' is listed..

PRedir = frmHub:GetRedirectAddress()

So if "Hub_Adress[curenthub]..":"..Hub_Adress[curentport].." is down it should auto update like:

frmHub:SetRedirectAddress(NextRedirInline)

and update this to temp.PRedir.

Then on next check if PRedir is online it should set that as redirect and delete the temp.PRedir. If PRedir is not online it should keep the temp.PRedir etc  etc ..
------------------------

Please let me know if its not explained well enough...

I know it can be done, just dont have the skill for it yet .. so please help me out :))


**Snooze
Title:
Post by: plop on 04 May, 2004, 10:22:53
kepp this sounds like a nice thing for your client, doing it on bcdc should be avoided @ any cost.
bcdc with luasockets has the bad side effect that it picks a random port without checking if it's free.
sooner or later it's gone pick a port which is in use, and the trouble starts.

plop
Title:
Post by: G?M on 11 May, 2004, 07:01:21
This is just another way checking server status, is there a way someone could make a table with all the network hubs in it?
can the info once checked be parsed?
also is there a way to clear the file portstat.txt after the check is over?
any insight would be greatly appreaciated!

Enjoy! :)

-- Network Status Checker By G?M?
-- Requested by Snooze
-- Requirements: PortQuery you can get it at
-- [URL]http://www.microsoft.com/downloads/details.aspx?familyid=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en[/URL]
-- once downloaded unzip it to the %Windir%/system32 directory
-- also the folder C:\NetCheck needs to be created
-- Thanks to Gamefreak for showing me PortQuery
-- PLEASE NOTE  PORT QUERY WILL ONLY WORK ON NT,2K AND XP!

Bot = "Netchecker"
dir = "C:\\NetCheck\\"

function Main()
frmHub:RegBot(Bot)
end

function DataArrival(user,data)
    if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")

if cmd == "!netcheck" then
        check()
        end
    end
end


function check()
-- portqry usage
-- -n servertocheck.com  < remote server to check
-- -e 411                < remote port to check


execute("portqry -n server.no-ip.com -e 411 > "..dir.."portstat.txt")
readfrom(dir.."portstat.txt");

local line = read("*a");
    if(line) then
    line = gsub(line, "\n", "\r\n");
    SendToAll(Bot, "\r\n"..line);
    end
end
Title:
Post by: [G-T-E]Gate? on 11 May, 2004, 10:03:40
Just did my daily read thru on whats been happening and found this thread, Interesting I must say .
 Now to the script and Server Querying,
Installed the script and PortQryV2. Ran the command and got the followiong responce,
wonder if its not meant to the responce to Netchecker Bot,
Would appreciate it , plus a question on "unknown service" last line. Why "unknown service" ?
Thanks  and what a nice way to start the morning :D



Querying target system called:

 sod.homedns.org.

Attempting to resolve name to IP address...


Name resolved to 81.229.30.244

querying...

TCP port 411 (unknown service): LISTENING
Title:
Post by: G?M on 11 May, 2004, 13:19:32
i'm not sure what services it can identify, more than likely its just the basic
telnet 23
ftp 21
http 80
etc
that is why the unknown service comes up in response to checking port 411.
Title:
Post by: kepp on 14 May, 2004, 02:13:59
yea, good idea plop, I think i have 9 - 12 diferent Client projects im working on!! But yea, I like the idea..
and thank you, i got another idea :D