Solved

Telnet HTTP stuck in batch

Posted on 2013-12-10
12
509 Views
Last Modified: 2013-12-31
I run the windows shell script below.  In batch it gets stuck and I need to hit ENTER for it to finish.  When run interactively, it runs fine with no breaks.

Please advise.


--- run_telnet.bat
wscript //B //Nologo %sh_dir%telnet_http.vbs


--- telnet_http.vbs
WScript.Timeout = 10

Set TelnetSession = CreateObject("WScript.Shell")
TelnetSession.run"telnet 192.168.x.y 80 -f telnet_log.txt"
TelnetSession.SendKeys("{Enter}")
WScript.Sleep 500

TelnetSession.SendKeys"GET /index.html HTTP/1.1"
TelnetSession.SendKeys("{Enter}")
TelnetSession.SendKeys"HOST: 192.168.x.y"
TelnetSession.SendKeys("{Enter}")
TelnetSession.SendKeys"USER-AGENT: Foobar"
TelnetSession.SendKeys("{Enter}")
TelnetSession.SendKeys("{Enter}")
WScript.Sleep 1000
TelnetSession.SendKeys("{Enter}")
WScript.Sleep 1000
TelnetSession.SendKeys("{Enter}")
WScript.Sleep 1000

TelnetSession.SendKeys("{Enter}")
WScript.Sleep 1000
0
Comment
Question by:flowerbloom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
12 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 39708212
That's a bad way to get a HTTP response. What's the purpose of it? You would be better off by using some more advanced techniques, like Web Automation (starting and controlling IExplore.exe) for sure.

But maybe your only issue with that script currently is that the Telnet window might not have focus, so should make sure the window is put on front of everything else with the Run.
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39708214
???
I don't understand.
I need the output from the HTTP request.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39708224
Try if using
TelnetSession.run "telnet 192.168.x.y 80 -f telnet_log.txt",1

Open in new window

works better.
At which state you need to press Enter manually? Is it performing any of the inputs before that?

Again, the SendKeys approach is very wobbly, if there are timing issues it doesn't work anymore.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Author Comment

by:flowerbloom
ID: 39708364
1. How would I run it?  From the command prompt/DOS? From VBS?
2. It finishes the work and hangs.  Clicking ENTER seems to happen after the work was done.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39708477
You should be able to start the VBS file (telnet_http.vbs) directly.
How about adding another SendKey ENTER to your VBS code?
As I can't test your code, I can't tell why you would need that, so just let us try.
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39722867
I added an extra ENTER and it does not help.  same results.
0
 
LVL 43

Expert Comment

by:Rob
ID: 39722927
Like Qlemo had said, you can call the vbs directly with no need to use a bat file.
Have you thought of using curl?
0
 
LVL 43

Expert Comment

by:Rob
ID: 39722932
http://curl.haxx.se/download.html#Win32 or just below is the 64 bit version

(EDIT) to be more specific and for what you need:  http://www.paehl.com/open_source/?download=curl_733_0.zip
0
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 39722953
so all your bat file needs to be:

--- run_curl.bat
%curl_dir%curl.exe 192.168.x.y 80 > curl_log.html
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 39749183
Works great! Thanks!
0
 
LVL 1

Author Closing Comment

by:flowerbloom
ID: 39749184
It works!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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