Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Detection of Internet connection

Mar
3
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 "[email protected]" 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.
 
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 "[email protected]" 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.

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
 
Hi all!

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.

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
 
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 "[email protected]" 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.

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
 

Similar threads

Back
Top