Jump to content

Tring to make an script to detect if I have internet


Swift
 Share

Recommended Posts

This works...like half the time...then does work other times...can anyone help me?

While 1
    InetGet("http://www.autoitscript.com")
    If @error = 0 Then ToolTip("No Internet", 1, 1)
    If Not @error Then ToolTip("", 1, 1)
    Sleep(2000)
WEnd
Link to comment
Share on other sites

That doesnt do what im looking for. Thanks anyway.

I tried this..But its not working :)

While 1
$INTERNET_CONNECTION_MODEM        = 0x1
$INTERNET_CONNECTION_LAN            = 0x2
$INTERNET_CONNECTION_PROXY        = 0x4
$INTERNET_CONNECTION_MODEM_BUSY  = 0x8
$INTERNET_RAS_INSTALLED          = 0x10
$INTERNET_CONNECTION_OFFLINE        = 0x20
$INTERNET_CONNECTION_CONFIGURED  = 0x40

    $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

    If $ret[0] then
     ;check type of connection
        $sX = ""
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM)    Then $sX = $sX & "MODEM" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_LAN)        Then $sX = $sX & "LAN" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_PROXY)    Then $sX = $sX & "PROXY" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF
        If BitAND($ret[1], $INTERNET_RAS_INSTALLED)      Then $sX = $sX & "RAS_INSTALLED" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE)    Then $sX = $sX & "OFFLINE" & @LF
        If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF
    Else
        $sX = "No Internet"
    Endif

    ToolTip($sX, 1, 1)
    Sleep(2000)
WEnd

EDIT: and I dont want to use BETA for it.

Edited by Swift
Link to comment
Share on other sites

This example may help you. It shows whether a connection is available and if Google is responding to a ping request.

Global Const $INTERNET_CONNECTION_MODEM = 0x1
Global Const $INTERNET_CONNECTION_LAN = 0x2
Global Const $INTERNET_CONNECTION_PROXY = 0x4
Global Const $INTERNET_CONNECTION_MODEM_BUSY = 0x8
Global Const $INTERNET_RAS_INSTALLED = 0x10
Global Const $INTERNET_CONNECTION_OFFLINE = 0x20
Global Const $INTERNET_CONNECTION_CONFIGURED = 0x40

$handle_wininet = DllOpen('WinInet.dll')

While 1
    $ret = DllCall($handle_wininet, "int", "InternetGetConnectedState", "int*", 0, "int", 0)
    If $ret[0] Then
        ;check type of connection
        $sX = ""
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM) Then $sX &= "MODEM" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_LAN) Then $sX &= "LAN" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_PROXY) Then $sX &= "PROXY" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX &= "MODEM_BUSY" & @CRLF
        If BitAND($ret[1], $INTERNET_RAS_INSTALLED) Then $sX &= "RAS_INSTALLED" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE) Then $sX &= "OFFLINE" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX &= "CONFIGURED" & @CRLF
        ;check to see if Google is online
        If Ping('www.google.com') Then
            $sX &= 'GOOGLE IS ONLINE'
            Sleep(3000)
        EndIf
    Else
        $sX = "No Internet"
    EndIf
    ToolTip($sX, 1, 1)
    Sleep(2000)
WEnd

Func OnAutoItExit()
    DllClose($handle_wininet)
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

This example may help you. It shows whether a connection is available and if Google is responding to a ping request.

Global Const $INTERNET_CONNECTION_MODEM = 0x1
Global Const $INTERNET_CONNECTION_LAN = 0x2
Global Const $INTERNET_CONNECTION_PROXY = 0x4
Global Const $INTERNET_CONNECTION_MODEM_BUSY = 0x8
Global Const $INTERNET_RAS_INSTALLED = 0x10
Global Const $INTERNET_CONNECTION_OFFLINE = 0x20
Global Const $INTERNET_CONNECTION_CONFIGURED = 0x40

$handle_wininet = DllOpen('WinInet.dll')

While 1
    $ret = DllCall($handle_wininet, "int", "InternetGetConnectedState", "int*", 0, "int", 0)
    If $ret[0] Then
        ;check type of connection
        $sX = ""
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM) Then $sX &= "MODEM" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_LAN) Then $sX &= "LAN" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_PROXY) Then $sX &= "PROXY" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX &= "MODEM_BUSY" & @CRLF
        If BitAND($ret[1], $INTERNET_RAS_INSTALLED) Then $sX &= "RAS_INSTALLED" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE) Then $sX &= "OFFLINE" & @CRLF
        If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX &= "CONFIGURED" & @CRLF
        ;check to see if Google is online
        If Ping('www.google.com') Then
            $sX &= 'GOOGLE IS ONLINE'
            Sleep(3000)
        EndIf
    Else
        $sX = "No Internet"
    EndIf
    ToolTip($sX, 1, 1)
    Sleep(2000)
WEnd

Func OnAutoItExit()
    DllClose($handle_wininet)
EndFunc

$google=DllCall("WinInet.dll","int","InternetCheckConnectionA","str",'http://www.google.com',"int",1,'int',0)

IF $google[0] Then MsgBox(262144,'','Google is online')

Link to comment
Share on other sites

  • 3 weeks later...

$var = Ping("www.google.com",1000)
If @error = 0 Then
    Msgbox(0,"Status","Online, roundtrip was:" & $var)
Else
    Msgbox(0,"Status","An error occured with number: " & @error)
EndIf

This should work :)

Edited by Chris86
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...