中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 19:00
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » Another question about sending IP to email using batch processing?
Printable Version  2,122 / 7
Floor1 nblue Posted 2006-06-16 11:16
初级用户 Posts 37 Credits 117
A few days ago, I posted a question in this forum about how to use batch processing to send the IP to the email, and got the pointers from the friends in the forum. I have benefited a lot, but I am really weak in this aspect of knowledge, and there is still a problem that cannot be solved. I have to post this post again to ask the experts for guidance.

Original batch processing code:
@echo off
for /f "tokens=2 delims=:" %%i in ('"ipconfig|findstr /I /c:"ip address""') do set a=%%i

echo NameSpace="http://schemas.microsoft.com/cdo/configuration/" >1.vbs
echo Set Email=CreateObject("CDO.Message") >>1.vbs
echo Email.From="your sending email address" >>1.vbs
echo Email.To="your receiving email address" >>1.vbs
echo Email.Subject="TEST" >>1.vbs
echo Email.Textbody="%a%" >>1.vbs
echo With Email.Configuration.Fields >>1.vbs
echo ^.Item(NameSpace^&"sendusing")=2 >>1.vbs
echo ^.Item(NameSpace^&"smtpserver")="SMTP address" >>1.vbs
echo ^.Item(NameSpace^&"smtpserverport")=25 >>1.vbs
echo ^.Item(NameSpace^&"smtpauthenticate")=1 >>1.vbs
echo ^.Item(NameSpace^&"sendusername")="username" >>1.vbs
echo ^.Item(NameSpace^&"sendpassword")="password" >>1.vbs
echo ^.Update >>1.vbs
echo End With >>1.vbs
echo Email.Send >>1.vbs

cscript c:\1.vbs
del c:\1.vbs

Problem: When connected to the Internet, the batch processing runs and can successfully send the IP to the email, but if not connected to the Internet, it will be wrong. How to modify the command so that the batch processing runs only when the system is connected to the Internet, and does not run or does not display errors when not connected to the Internet?
Floor2 bagpipe Posted 2006-06-16 11:31
银牌会员 Posts 425 Credits 1,144 From 北京
cscript c:\1.vbs 1>nul 2>nul||echo Sending error...

No experiment has been conducted, please the original poster to report the situation after the experiment, thank you........
Floor3 bagpipe Posted 2006-06-16 12:02
银牌会员 Posts 425 Credits 1,144 From 北京
You can try the following code, the above may not work:

@echo off
for /f "tokens=2 delims=:" %%i in ('"ipconfig|findstr /I /c:"ip address""') do set a=%%i
echo on error resume next >1.txt
echo NameSpace="http://schemas.microsoft.com/cdo/configuration/" >>1.vbs
echo Set Email=CreateObject("CDO.Message") >>1.vbs
echo Email.From="your sending email address" >>1.vbs
echo Email.To="your receiving email address" >>1.vbs
echo Email.Subject="TEST" >>1.vbs
echo Email.Textbody="%a%" >>1.vbs
echo With Email.Configuration.Fields >>1.vbs
echo ^.Item(NameSpace^&"sendusing")=2 >>1.vbs
echo ^.Item(NameSpace^&"smtpserver")="SMTP address" >>1.vbs
echo ^.Item(NameSpace^&"smtpserverport")=25 >>1.vbs
echo ^.Item(NameSpace^&"smtpauthenticate")=1 >>1.vbs
echo ^.Item(NameSpace^&"sendusername")="username" >>1.vbs
echo ^.Item(NameSpace^&"sendpassword")="password" >>1.vbs
echo ^.Update >>1.vbs
echo End With >>1.vbs
echo Email.Send >>1.vbs
echo if err.number^<^>0 then>>1.vbs
echo wscript.echo 发送错误......>>1.vbs
echo wscript.quit >>1.vbs
echo end if >>1.vbs

cscript c:\1.vbs
del c:\1.vbs
Not tested, please report after testing, thank you
Floor4 nblue Posted 2006-06-16 18:04
初级用户 Posts 37 Credits 117
Test platform: WINDOWS XP
Test models: 1, IBM T60 (new system) 2, compatible machine
Number of tests: more than 20 times
Let the original batch processing be A, and the batch processing with hidden error function be B. Test method:
1. Under network connection: Running A can successfully send IP to the email, but there is a window appearing, which disappears in about 15 seconds; running B has an error prompt "c:\1.vbs<18,14>microsoft vbscript compiler error: invalid character", there is a window appearing, and the window disappears in about 10 seconds.
2. Under offline condition: Running A has a running window appearing, on IBM T60 it flashes by in a flash, and on the compatible machine it takes a few seconds to disappear. When running B, on IBM T60 it flashes by in a flash. It hasn't been tested on the compatible machine yet
Floor5 nblue Posted 2006-06-16 18:05
初级用户 Posts 37 Credits 117
I'm testing, and I find that the IP isn't sent every time the batch script runs. It succeeds in sending only about once every four or five runs.
Floor6 electronixtar Posted 2006-06-16 18:12
铂金会员 Posts 2,672 Credits 7,493
This should be a problem with the email server, it's slow to respond~~ I also need to try more than 5 times to connect to QQ Mail~~
Floor7 nblue Posted 2006-06-16 18:18
初级用户 Posts 37 Credits 117
Originally posted by electronixtar at 2006-6-16 18:12:
This should be a problem with the email server, it's slow to respond~~ I also need to try more than 5 times to connect to QQ Mail~~

Yes
Floor8 nblue Posted 2006-06-16 18:30
初级用户 Posts 37 Credits 117
Hehe, the expert netizen bagpipe made a "Buddha" character, and I imitated it to make a "God" character. Please excuse the crudeness.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023