Solved

telnet from ASP to send a simple command?

Posted on 2004-10-24
1,925 Views
Last Modified: 2007-12-19
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.
0
Question by:thedogeater
    16 Comments
     

    Author Comment

    by:thedogeater
    I should say as well this is VBScript not .NET ASP
    0
     
    LVL 2

    Expert Comment

    by:larellnielsen
    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
    0
     
    LVL 14

    Expert Comment

    by:huji
    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
    0
     

    Author Comment

    by:thedogeater
    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
    0
     
    LVL 2

    Expert Comment

    by:larellnielsen
    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
    0
     
    LVL 14

    Expert Comment

    by:huji
    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
    0
     
    LVL 2

    Expert Comment

    by:larellnielsen
    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
    0
     
    LVL 14

    Expert Comment

    by:huji
    Very correct, LaRell.
    Please send anything here, thedogeater.
    Huji
    0
     

    Author Comment

    by:thedogeater
    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.
    0
     
    LVL 14

    Expert Comment

    by:huji
    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
    0
     

    Author Comment

    by:thedogeater
    creating the batch script is a biger problem for me now.
    0
     
    LVL 14

    Expert Comment

    by:huji
    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
    0
     

    Author Comment

    by:thedogeater
    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.
    0
     
    LVL 14

    Expert Comment

    by:huji
    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
    0
     

    Author Comment

    by:thedogeater
    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....
    0
     
    LVL 14

    Accepted Solution

    by:
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    931 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now