China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-09-23 18:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Another question about sending IP to email using batch processing? View 2,120 Replies 7
Original Poster Posted 2006-06-16 11:16 ·  中国 广东 深圳 电信
初级用户
Credits 117
Posts 37
Joined 2006-06-08 12:23
20-year member
UID 56740
Status Offline
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?
Floor 2 Posted 2006-06-16 11:31 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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........
Floor 3 Posted 2006-06-16 12:02 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
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
Floor 4 Posted 2006-06-16 18:04 ·  中国 广东 深圳 电信
初级用户
Credits 117
Posts 37
Joined 2006-06-08 12:23
20-year member
UID 56740
Status Offline
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
Floor 5 Posted 2006-06-16 18:05 ·  中国 广东 深圳 电信
初级用户
Credits 117
Posts 37
Joined 2006-06-08 12:23
20-year member
UID 56740
Status Offline
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.
Floor 6 Posted 2006-06-16 18:12 ·  IANA 局域网IP(Private-Use)
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
21-year member
UID 42173
Gender Male
Status Offline
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~~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 7 Posted 2006-06-16 18:18 ·  中国 广东 深圳 电信
初级用户
Credits 117
Posts 37
Joined 2006-06-08 12:23
20-year member
UID 56740
Status Offline
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
Floor 8 Posted 2006-06-16 18:30 ·  中国 广东 深圳 电信
初级用户
Credits 117
Posts 37
Joined 2006-06-08 12:23
20-year member
UID 56740
Status Offline
Hehe, the expert netizen bagpipe made a "Buddha" character, and I imitated it to make a "God" character. Please excuse the crudeness.
Forum Jump: