Jump to content
Sign in to follow this  
Xyborg

Server status through cmd ping.

Recommended Posts

Xyborg

Ok. I've browsed the forums for a couple hours now and tried a few things that didn't work at all. So, it's time to resort to pestering you people.

This is the order of things I want to do.

Run CMD

Ping IP

If text = Result Timed Out. > activate IRC window and send "Status = Down"

If text = Reply from IP: > activate IRC window and send "Status = Up"

And I want this to be running at all times, checking the ping every few minutes or so. Below is what I have thus far. Just the basics.

Run("cmd", "")
WinActivate ( "C:\WINDOWS\system32\cmd.exe", "" )
    Sleep (500)
Send("Ping 127.0.0.1{Enter}")
    Sleep (5000)
    ;Status = Up ifcheck
WinActivate ( "#AddictRO", "" )
;Send("Status = Up{Enter}")
    ;Status = Down ifcheck (else)
WinActivate ( "#AddictRO", "" )
;Send("Status = Down{Enter}")
WinClose ( "C:\WINDOWS\system32\cmd.exe", "" )

Any help would be greatly appreciated. I'm going to continue trying to find a way to get thing to notice the windows text.

And another thing I want to do is, when one of my dos programs starts looping (Don't ask) it shuts down that program and all that are affiliated with it, waits 5 minutes, then starts them up again. All I really need to know is how to get autoit to do certain things when certain text is displayed in the dos window.

That's the problem I'm having the most.

Edited by Xyborg

Share this post


Link to post
Share on other sites
Andre

Hi,

in the latest autoit there is an ping supported

Pings a host and returns the roundtrip-time.

Ping ( address or hostname [, timeout] )

Parameters

address/hostname Can be i.e. "www.hiddensoft.com" or "178.50.76.4".

timeout [optional] Is the time to wait for an answer in milliseconds (default is 4000).

Return Value

Success: Returns the roundtrip-time in milliseconds ( greater than 0 ).

Failure: Returns 0 if host is not pingable or other network errors occured and sets @error. (See Remarks)

Remarks

When the function fails (returns 0) @error contains extended information:

1 = Host is offline

2 = Host is unreachable

3 = Bad destination

4 = Other errors

Andre


What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!

Share this post


Link to post
Share on other sites
Xyborg

Ok. I'm still totally lost :). And that won't help me with my second task either. I need to know how to read from the stupid dos window. Gah. And that ping thind didn't help me at all either. I ran my script and it didn't do squat.

I'm well aware that I'm probably missing something, but 3 hours of just trying to get AutoIt to read text in the dos window is really starting to get on my nerves.

[Edit]

Oh. Can that ping function specify a specific port? If so, I assume it's just IP:Port?

Edited by Xyborg

Share this post


Link to post
Share on other sites
SlimShady

Does this help you a little?

If ServerOnline("127.0.0.1") Then    ;...
;Status = Up ifcheck
WinActivate ( "#AddictRO", "" )
;Send("Status = Up{Enter}")
;Status = Down ifcheck (else)
WinActivate ( "#AddictRO", "" )
;Send("Status = Down{Enter}")

Func ServerOnline($Host)
   Return Ping($Host)
EndFunc
Edited by SlimShady

Share this post


Link to post
Share on other sites
Blue_Drache

Ok.  I'm still totally lost :).  And that won't help me with my second task either.  I need to know how to read from the stupid dos window.  Gah.  And that ping thind didn't help me at all either.  I ran my script and it didn't do squat.

I'm well aware that I'm probably missing something, but 3 hours of just trying to get AutoIt to read text in the dos window is really starting to get on my nerves.

<{POST_SNAPBACK}>

If you're using standard mIRC windows set to the desktop then the command to change the topic is a default of "/topic <insert text here>" I believe. If you don't have Ops (@) just use a controlsend to the editbox. Use the window spy to get the controlID of the editbox.

AutoIt cannot read the DOS box without screen scraping.

Opt("WinTitleMatchMode",2)
Run(@Comspec)
WinWaitExist("cmd.exe")
WinActivate("cmd.exe")
Send("ping 127.0.0.1")
Sleep(3000)
WinActivate("cmd.exe")
Send("!{space}ES{enter}")
$dos_clip = Clipget()

The contents of the screen scrape are put into the variable $dos_clip. From there, just use standard string manipulation tools, IE StringInStr(), StringMid(), etc.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
Xyborg

Well. I screwed around with the stupid ping thing and it works better than I thought.

$var = Ping("127.0.0.1",1000)
If $var Then
WinActivate("mIRC - ", "")
Send("Status = ^k9Online.{Enter}")
Else
WinActivate("mIRC - ", "")
Send("Status = ^k4Offline.{Enter}")
EndIf

Now, what I want to do, is find a way for it to send that info to the channel without activating the window and interrupting what I'm doing? Is this possible?

Or, if possible, have it run on a totally different user profile (WinXP) and then I don't have to worry about it.

Edited by Xyborg

Share this post


Link to post
Share on other sites
Blue_Drache

Well.  I screwed around with the stupid ping thing and it works better than I thought.

$var = Ping("127.0.0.1",1000)
If $var Then
WinActivate("mIRC - ", "")
Send("Status = ^k9Online.{Enter}")
Else
WinActivate("mIRC - ", "")
Send("Status = ^k4Offline.{Enter}")
EndIf

Now, what I want to do, is find a way for it to send that info to the channel without activating the window and interrupting what I'm doing?  Is this possible?

Or, if possible, have it run on a totally different user profile (WinXP) and then I don't have to worry about it.

<{POST_SNAPBACK}>

What you want to look up is ControlSend()

It sends commands text to windows even when they are hidden, minimised, underneath other windows.....as long as the program is running and has controls you can tinker with.....

Get the controlID with the Window Info Tool (Window Spy)

Edit: changed wording...couldn't figure out how to strikeout text.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
RPC

When it comes to interacting with DOS programs I have found it easier to redirect the output of the program to a file and then search the file for the results.

Here's a simple example:

RunWait(@ComSpec &' /C Ping 192.168.0.100 >C:\T.TXT','',@SW_HIDE)
$Test = FileRead('C:\T.TXT',1024)
FileDelete('C:\T.TXT')
If StringInstr($Test,'Request timed out') Then
  Msgbox(4096,'Notice','System Down')
Else
  Msgbox(4096,'Notice','System UP')
EndIf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.