Jump to content

check connection to IP


Dag
 Share

Recommended Posts

welcome all

this is my first post :lmao:

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 :ph34r:

Link to comment
Share on other sites

welcome all

this is my first post :lmao:

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 :ph34r:

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

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

$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

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 :lmao: Should do the trick

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

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

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 :lmao: )?

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.

Link to comment
Share on other sites

  • Moderators

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 :lmao: )?

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() :ph34r:

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

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 :lmao: )?

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 :ph34r:

#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 :geek:

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

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 :lmao: )?

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 :ph34r:

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 :geek:

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 by Dag
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...