Dag Posted October 11, 2006 Share Posted October 11, 2006 welcome all this is my first post i need to make a program what shutdown my PC when i lost connection to IP. maybe netstat program will be usefull. i'll be very happy if you give me some tips thanks in advice, and sorry for my english Link to comment Share on other sites More sharing options...
MadBoy Posted October 11, 2006 Share Posted October 11, 2006 welcome all this is my first post i need to make a program what shutdown my PC when i lost connection to IP. maybe netstat program will be usefull. i'll be very happy if you give me some tips thanks in advice, and sorry for my english Check commands in help file: ping, shutdown, sleep and put it in while loop.Hope that's what you meant? While 1 $ping_result = ping("192.168.1.1") sleep(200) If $ping_result = 0 Then Shutdown(2) EndIf Wend I think that should do the trick. Just play with sleep function so it would do it once per 2-5minutes and not all the time. My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
Dag Posted October 12, 2006 Author Share Posted October 12, 2006 i try this but it didn't work =/ i also try to ping on command line 206.82.200.11 but the serwer doesen't respond. i see i'm connected to this serwer only in netstat can i filter netstat? ps. i check in help file ^^ Link to comment Share on other sites More sharing options...
MadBoy Posted October 12, 2006 Share Posted October 12, 2006 $host = "192.168.1.1" While 1 $ping_result = ping($host) sleep(2000) If $ping_result = 0 Then MsgBox(1,1,"Server will now reboot. Can't ping " & $host) Shutdown(6) Exit EndIf Wend It does work. If no connection to $host is detected then computer should reboot. Script pings that ip every 2seconds. Change it to larger value or you will get nice load ;p My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
MadBoy Posted October 12, 2006 Share Posted October 12, 2006 Well as for server that doesn't respond to ping it's more complicated. It means that server has ICMP blocked. You can either do 'telnet ' to port that is open on that server and that way make sure it's up. Or you can as you said use netstat output (but you have to be connected to that server, otherwise netstat will show you nothing). It's a bit harder but oh well here it goes: Dim $Host = "YOUR IP GOES HERE" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(10) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then MsgBox(1,1,"Host is active") Next You gotta add some things, play with it etc Should do the trick My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
MadBoy Posted October 12, 2006 Share Posted October 12, 2006 Dim $Host = "your host here" Dim $host_is_active = "No" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(10) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then MsgBox(1,1,"Host is active") $host_is_active = "Yes" EndIf If $i = $NetstatOutput[0]-1 AND $host_is_active <> "Yes" Then MsgBox(1,1,"Host isn't active - Rebooting") ;Shutdown(6) EndIf Next this way it's better althought i realy don't see this being solution to any problem ;p My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
AzKay Posted October 12, 2006 Share Posted October 12, 2006 Maybe to a specific port? TCPStartup() TCPConnect("192.168.1.1", $PORT) ;replace port with the port number If @Error Then MsgBox(0, "", "Offline, Rebooting") Shutdown(6) TCPShutdown() Exit Else MsgBox(0, "", "Online") EndIf # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Uten Posted October 12, 2006 Share Posted October 12, 2006 Hi and welcome.... i need to make a program what shutdown my PC when i lost connection to IP. ...Im a bit lost are we talkning about a specific server or when you have lost your public ip (no public ip no connection )?There is a _MyIP (or is it _PublicIp() ?) function in the UDF collection in the helpfile. Look under Network. And take a look at the source you will learn a lot from it. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 12, 2006 Moderators Share Posted October 12, 2006 Hi and welcome.Im a bit lost are we talkning about a specific server or when you have lost your public ip (no public ip no connection )?There is a _MyIP (or is it _PublicIp() ?) function in the UDF collection in the helpfile. Look under Network. And take a look at the source you will learn a lot from it._GetIP() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MadBoy Posted October 12, 2006 Share Posted October 12, 2006 (edited) Hi and welcome. Im a bit lost are we talkning about a specific server or when you have lost your public ip (no public ip no connection )? There is a _MyIP (or is it _PublicIp() ?) function in the UDF collection in the helpfile. Look under Network. And take a look at the source you will learn a lot from it. Mmm then i kinda misunderstood the problem #include <Inet.au3> While 1 $PublicIP = _GetIP() ;MsgBox(0, "[color="#ffffff"]IP[/color] Address", "Your [color="#ffffff"]IP[/color] Address is: " & $PublicIP) If $PublicIP = -1 Then MsgBox(1,1, "No connection to INET") Shutdown (6) EndIf sleep(3000) Wend almost straight from help Edited October 12, 2006 by MadBoy My little company: Evotec (PL version: Evotec) Link to comment Share on other sites More sharing options...
Dag Posted October 12, 2006 Author Share Posted October 12, 2006 (edited) Hi and welcome. Im a bit lost are we talkning about a specific server or when you have lost your public ip (no public ip no connection )? There is a _MyIP (or is it _PublicIp() ?) function in the UDF collection in the helpfile. Look under Network. And take a look at the source you will learn a lot from it. i try to explain it clearlier i play one online game and sometimes i leave my comp running when i go out. i'd like to make program what shutdown my PC when i get disconnect from game serwer 206.82.200.11:55901 thanks for all answers, i really apreciate your help madboy, i'll try yous netstat solution after tests i write here my effects edit: Dim $Host = "your host here" Dim $host_is_active = "No" Dim $NetstatOutput $Netstat = Run(@ComSpec & " /c netstat", '', @SW_HIDE, 2) While 1 $NetstatData = StdoutRead($Netstat) If @error Then ExitLoop If $NetstatData Then $NetstatOutput &= $NetstatData Else Sleep(10) EndIf WEnd $NetstatOutput = StringStripWs($NetstatOutput, 6) $NetstatOutput = StringSplit($NetstatOutput, @CRLF) For $i = 1 To $NetstatOutput[0] If StringInStr($NetstatOutput[$i], $Host) Then MsgBox(1,1,"Host is active") $host_is_active = "Yes" EndIf If $i = $NetstatOutput[0]-1 AND $host_is_active <> "Yes" Then MsgBox(1,1,"Host isn't active - Rebooting") ;Shutdown(6) EndIf Next this way it's better althought i realy don't see this being solution to any problem ;p work greate, thx very much i modify your script to check 6 serwers, and i replace msgbox witch traytip (more comfortable for me) thx again Edited October 12, 2006 by Dag Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now