Link to home
Start Free TrialLog in
Avatar of thedogeater
thedogeater

asked on

telnet from ASP to send a simple command?

Is there any way in a ASP I can create a telnet session wait for a prompt to return (or perhaps just wait for a few seconds) and then send a command? I don't need to send any login information or the like just a command which is an ordinary text string.
Avatar of thedogeater
thedogeater

ASKER

I should say as well this is VBScript not .NET ASP
You will not be able to interact directly but you could create a DLL to do the heavy lifting and call that from ASP.

LaRell
Yes there probably is. If you can do something from command prompt, then you can do it from within ASP using a speical feature named Wscript Shell.
An example is here:
You can type "nslookup -type=mx www.yahoo.com" to find the IP addresses of Yahoo mail servers. What if you want to do it from within asp? ASP by itself does not have a utility to perform a Name Server Lookup, so... this article shows you how it is done:
http://www.asp101.com/articles/hojjat/mxlookup/default.asp
Conclusion: May be we can manage it to perform a telnet connection (even) this way. I need your commands (which you can run from command prompt to work with that remote server) and will try to write a code (if I can) to do it from within ASP.
Wish I can help
Huji
The commands are simple in each case I need to only send one pice of text. I each case I just wish to send commands to certain IPs so I click on button 1 and it telnet to IP A and sends 'abc' click on button 2 and it sends '123' to IP B
I would caution you against do something like this. By utilizing the WSH you are going to have to expose areas that should be secured. Although it may be nice to do these type of function straight from ASP, always err on the side of percaution.

LaRell
All right.
It seems to be easy. Please send me a line of that command, and I'll try to manage it for you.
And larellnielsen, told some important point sooner than I would do! This is correct. See, when you are connecting to another computer with WScript Shell, or with XMLHTTP (the second one is something like, ASP opens a web browser, goes to a web site, and then stores the HTML passed to him from that web site, to you, so that you can use it; You may have noticed XMLHTTP in that ASP101 article too), you must accept the risk that, you may be at risk. But the amount of risk is just no more than when you connect to the computers with telnet yourself. ASP just does what you do, and the risk is just the same.
Waiting for your one line command.
Huji
Actually I was talking more towards exposing WSH within ASP. XMLHTTP is fine because it works more like a COM object than WSH. WSH is integrated into your OS :o( so it requires that you lower your security so that you can access it.

LaRell
Very correct, LaRell.
Please send anything here, thedogeater.
Huji
Thanks it does not help me much however. I would need to see how some code to do this would work. Perhaps even if I could have a batch script to the telneting and subsequent sending of the command, then it is simple to call this from ASP no?
Security is not a concern, as this is available only on an trusted internal network.
Yes it is possible to be called from ASP! That's what I say. From within ASP you can call the batch file! This is the point I'm trying to make you catch.
Please send me a sample batch file. And I'll send you the ASP code. Let's give it try, huh?
Waiting for your action
Wish I can help,
Huji
creating the batch script is a biger problem for me now.
All right, we may manage it too! Just answer to this question:
How do you cannot to those telnet remotes now, by typing some things in Comand Prmopt? Starting with:
telnet IP_ADDRESS
and so on?
If yes, just type all of those, here in the post box, and send them to me!
Huji
Indeed I do I telnet to say 10.0.0.2 wait for the prompt and type 'Command1' or 'Command2' for example. I dont know how I can automate the whole thing.
is it something like this:
You first go to command prompt. Then you type:
telnet 10.0.0.2
Then you hit enter. Then you type command1. Again enter. Is it?
Then try this:

telnet 10.0.0.2
command1
...

now save it in a file in notepad. Then change the extension of the file from TXT to BAT and double click on it. It will automatically do the stuff. If it worker, then let's do it from ASP.
Waiting for your commnet,
Huji
Hi Huji,

Thanks for you help but your script does not work the telnet command does not return untill it has finshed so can not take the input form the line bleow....
ASKER CERTIFIED SOLUTION
Avatar of huji
huji
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial