#145334 - 2005-08-11 01:37 PM
Reading/Writing from /to Command prompt
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Hi, Please excuse me. I am new to Kixtart. Using Kixtart, is it possible to write automated scripts which can READ from & WRITE to “Command Prompt” windows.
Basically, my issue is that I want to check accessibility to several IPs. These IPs have several ports open. Using Telnet, I want to check if the ports are open or not. Thus, on the command prompt window, if I see the statement 'Could not open connection to the host.. Connect failed' , it means the port is NOT opened. Thus, if I am able to read from the command prompt windows, the above thing wud be achieved. If anybody knows better method of checking the accessibility, please let me know. Thanks in advance.
|
Top
|
|
|
|
#145337 - 2005-08-11 02:50 PM
Re: Reading/Writing from /to Command prompt
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
look into WSHPipe() from the udf forum.
It will capture the output from a cndline app, and dump the output into an array to make it easier to parse.
Otherwise, you will have to redirect output into a text file and then read the file into an array, etc...
|
Top
|
|
|
|
#145340 - 2005-08-12 11:05 AM
Re: Reading/Writing from /to Command prompt
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Checking the value of @error does not help.
I tried $rc=WshPipe("telnet SOME I.P. 80")
For both the open, closed ports, it displayed --> 0 | The operation completed successfully.
I also checked all the commands of telnet. Its not possible to redirect its output.
I just want to write a script that will automate the telnet process. i.e. i will take the list of I.P. from a file and using the script telnet to all these I.P. If the port is NOT open then I will get an error 'Could not open connection to the host'. This error will be recorded using kixtart (somehow, but unfortunately I dont know & thats what I am asking) Is it possible using Kixtart. Please help.
Edited by Ziangi_Jones (2005-08-12 11:09 AM)
|
Top
|
|
|
|
#145341 - 2005-08-12 12:34 PM
Re: Reading/Writing from /to Command prompt
|
Witto
MM club member
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
If I try Shawn's advise Code:
Break On Shell "PING "+@WKSTA ? @ERROR": "@SERROR Shell "PING 192.168.222.3" ? @ERROR": "@SERROR
I know that 192.168.222.3 is non-existant The @ERROR is 1 and @SERROR tells me the function is wrong.
Edited by Witto (2005-08-12 12:36 PM)
|
Top
|
|
|
|
#145344 - 2005-08-12 02:35 PM
Re: Reading/Writing from /to Command prompt
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Code:
Shell 'PortQry.exe -n '+$ipaddr+' -e 135 -nr -q' $PC = iif(@ERROR,'Not Windows','Windows') ? $pc
Edited by Radimus (2005-08-12 02:58 PM)
|
Top
|
|
|
|
#145345 - 2005-08-12 02:37 PM
Re: Reading/Writing from /to Command prompt
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Expanding on Witto's comments, and assuming your looking to test just accessibility versus whether the telnet ports are specificically open or not, this code works. Just change the $WKSTA variable to test good and bad hostnames.
Code:
break on
$wksta = @WKSTA
shell '%comspec% /c ping -n 2 $wksta | find /i "TTL=" >NUL 2>NUL'
if @ERROR = 0 ?"$wksta is accessible!" else ?"$wksta is not accessible!" endif
exit 0
Or - are you looking to test specifically whether telnet is available ?
-Shawn
|
Top
|
|
|
|
#145349 - 2005-08-12 04:03 PM
Re: Reading/Writing from /to Command prompt
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Me and Doc worked on a script a while back that "kind of" does what you want... its definately not the most efficient way to do it, but at the time, I think it was all that was needed.
MX Record lookup help
I modified the MailServerUp function (discussed in the above thread) into the code below. Requires EndProcess() UDF.
Code:
Function TNServerUp($server,$port) Dim $output,$,$fh,$line,$path $output='%temp%\output.txt' If Exist($output) Del $output EndIf Run '%comspec% /c telnet -f ' + $output + ' ' + $server + ' ' + $port Sleep 2 $=EndProc('telnet.exe') Sleep 1 $fh=FreeFileHandle() If Open($fh,$output)=0 $line=ReadLine($fh) While @ERROR=0 If Left($line,3)=220 $TNServerUp=1 EndIf $line=ReadLine($fh) Loop $=Close($fh) EndIf If Exist($output) Del $output EndIf EndFunction
|
Top
|
|
|
|
#145350 - 2005-08-22 11:52 AM
Re: Reading/Writing from /to Command prompt
|
AstaaLavista
Starting to like KiXtart
Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
|
Hi All, Sorry for the late reply. I had been out of station.
Quote:
Or - are you looking to test specifically whether telnet is available ?
-Shawn
This was what I was looking for. I will try the code sent by Allen. I hope my problem will be solved. Thanks a lot
|
Top
|
|
|
|
#145352 - 2005-08-22 04:03 PM
Re: Reading/Writing from /to Command prompt
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
The UDF above "determines" a connection by getting a return code by making a connection to a SMTP server via telnet. I admit, I have not tested this on any other type of telnet server. It may be possible to modify the udf above to meet your needs but you might also consider the other suggestions in this thread.
If you want to use the UDF I wrote, you will need to run the telnet command in a command window with the logging feature enabled (telnet -f telnet.log xxx.xxx.xxx.xxx p). Then look at the log to see if it gives you a consistent connection line. Then modify the UDF above to look for that string, changing this line: If Left($line,3)=220.
You might also post your results and we might be able to help.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 373 anonymous users online.
|
|
|