Page 1 of 2 12>
Topic Options
#145334 - 2005-08-11 01:37 PM Reading/Writing from /to Command prompt
AstaaLavista Offline
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
#145335 - 2005-08-11 02:04 PM Re: Reading/Writing from /to Command prompt
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Assuming your doing some sort of SHELL statement that runs a program that produces this output. Suggest you try querying the value of @ERROR to see if a meaningfull number if returned, that can be checked with an IF statement.

Try putting this after the SHELL statement and advise:

? @ERROR

-Shawn

Top
#145336 - 2005-08-11 02:32 PM Re: Reading/Writing from /to Command prompt
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
Hi Shawn,
I am sorry, but I didn't get ur suggestion.

Basically, I want to know if its possible to READ from any COMMAND PROMPT window, using KIXTART. If yes, then how ?

Top
#145337 - 2005-08-11 02:50 PM Re: Reading/Writing from /to Command prompt
Radimus Moderator Offline
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...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#145338 - 2005-08-11 03:05 PM Re: Reading/Writing from /to Command prompt
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I guess what I'm saying is that you probably dont have to read the command line ... whatever program is displaying that (what looks like) an error message, is probably also setting the value of @ERROR, and you may be able to check that instead (basically make it easier on yourself).
Top
#145339 - 2005-08-11 03:54 PM Re: Reading/Writing from /to Command prompt
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you want to chaeck ports, there is a better way than to telnet and scrape the screen. I use a utility called portchek.exe to test for open ports.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#145340 - 2005-08-12 11:05 AM Re: Reading/Writing from /to Command prompt
AstaaLavista Offline
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 Offline
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
#145342 - 2005-08-12 01:02 PM Re: Reading/Writing from /to Command prompt
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there is telnet object in howard bullocks hoby-objects library dll.

anyone care to pass the link?
_________________________
!

download KiXnet

Top
#145343 - 2005-08-12 02:05 PM Re: Reading/Writing from /to Command prompt
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Sure.

http://home.comcast.net/~habullock/habobjects.htm
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#145344 - 2005-08-12 02:35 PM Re: Reading/Writing from /to Command prompt
Radimus Moderator Offline
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)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#145345 - 2005-08-12 02:37 PM Re: Reading/Writing from /to Command prompt
Shawn Administrator Offline
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
#145346 - 2005-08-12 02:49 PM Re: Reading/Writing from /to Command prompt
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It is a common practice to use telnet to test other than telnet ports and I suspect that is what this is about. While telnet is fine from the commandline, there are better ways as suggested by my and Rad's posts.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#145347 - 2005-08-12 03:34 PM Re: Reading/Writing from /to Command prompt
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
IIRC UDP ports will not accept a TCP connection (three way connection negotiation fails) so telnet is of limited use.

Portchek or a port scanning tool like nmap (www.insecure.org) are much better prospects.

Top
#145348 - 2005-08-12 03:45 PM Re: Reading/Writing from /to Command prompt
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Code:
Break on
;Uses NetView() UDF from http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000059
Call "C:\KiXScripts\netview.udf"
$netview = netview("@LDOMAIN")
if @error = 0
for each $computer in $netview
$ShellCMD="C:\KiXScripts\portchek -h "+$computer+" 36794"
Shell $ShellCMD
If @error
"No listener on port 36794 of "+$computer ?
Else
"YIKES! LISENER FOUND ON PORT 36794 OF "+$computer ?
Beep
EndIf
next
endif


"That all folks!"?
Get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#145349 - 2005-08-12 04:03 PM Re: Reading/Writing from /to Command prompt
Allen Administrator Offline
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 Offline
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
#145351 - 2005-08-22 03:17 PM Re: Reading/Writing from /to Command prompt
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
I tried the script by entering the I.P. address & the port. But, for both valid & invalid ports it gives the same message "System did not respond".
I copied the entire code of "MX Record lookup help " & also of Allen, but was unlucky to get any end result. i dont think i missed anything here.

I wud like to repeat my problem once again. i have a I.P. address. I want to design a script given I.P & port, i do the telnet. If i get the error message "Could not open connection to the host", it means the port is NOT opened.
I will record the result from the window.

I think i m behaving like a dumb, but sadly, i m not understanding what to do.
Plz. help.

Top
#145352 - 2005-08-22 04:03 PM Re: Reading/Writing from /to Command prompt
Allen Administrator Offline
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
#145353 - 2005-08-23 06:27 AM Re: Reading/Writing from /to Command prompt
AstaaLavista Offline
Starting to like KiXtart

Registered: 2005-08-11
Posts: 111
Loc: Gujarat, India.
I tried the following on the command prompt:
telnet -f abc.txt port.

Surprisingly, abc.txt was modified (seeing from the timestamp), but nothing was written into it.

Should I enable logging from somewhere. I tried 'set logging on' but I got an error, 'Environment variable logging not defined'.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 833 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.079 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org