1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Detection of Internet connection

Discussion in 'Support' started by mjja, Oct 17, 2009.

  1. mjja

    Joined:
    Mar 13, 2009
    Messages:
    3
    Likes Received:
    0
    Hi all!

    I have a log file and I want to send it automatically to a specific e-mail address when some conditions are true. Ok, this is easy with SENDMAIL command. But I have a Huawei 3G modem so my Internet connection may be in offline. What's the easiest way to detect if it's in offline or online?

    I mean, I want to make something like this:

    IFF %_CONNECTED == 1 THEN
    ECHO %_TIME - Sending log file.
    SENDMAIL "ad@dre.ss" Log @Log.log
    ECHO %_TIME - Ok.
    ELSE
    ECHO %_TIME - No Internet connection. Log didn't sent.
    ENDIFF

    Yes, _CONNECTED doesn't exist, but does some else?

    I have:

    TCC 9,02.157 Windows Vista [Version 6,0,6002]
    TCC Build 157 Windows Vista Build 6002 Service Pack 2

    Thanks forehand!

    -Mikko.
     
  2. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi,
    You could use @ping to determine if you can PING a known host. For example;

    Code:
    echo %@ping[www.jpsoft.com]
    
    If this command returns a negative number, then there was an error.

    You could copy a file from a known host as a test. For example;

    Code:
    copy "http://www.jpsoft.com" jpsoft.htm
    
    When I do this, an error level of 2 is returned if the file could not be copied.

    You could use the Windows API InternetGetConnectedState call, available in the WININET.DLL. This can be called from TCMD via the @WINAPI function.

    Joe
     
  3. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi,
    Another method is to check your IP address using the @IPADDRESS function.

    When my system is not connected to the LAN/WAN, it returns 127.0.0.1

    When my system is connected to the LAN/WAN, it returns 192.168.0.102. Your IP number will be different.

    No computer connected to the Internet, or any other TCP/IP compliant network, can identify itself as 127.0.0.1

    Note that I used the IPCONFIG command with the /RELEASE and /RENEW options to test this. Best to check with your system and hardware to verify if this will work for you.

    Joe
     
  4. mjja

    Joined:
    Mar 13, 2009
    Messages:
    3
    Likes Received:
    0
    This works well.
    Thanks!


    Mikko.
     
  5. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    You need the IP name or IP address of the default gateway you are using (probably specified by your ISP). For illustration only, let's say it's 10.9.8.7 :


    set _connected=`%@if[%@exec[ping -n 1 10.9.8.7 > nul] eq 0,1,0]`

    echo %_connected
    1

    if %_connected eq 1 echo yup
    yup
     

Share This Page