• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

Telnet HTTP stuck in batch

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
flowerbloom
Asked:
flowerbloom
  • 5
  • 3
  • 3
1 Solution
 
QlemoC++ DeveloperCommented:
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
 
flowerbloomAuthor Commented:
???
I don't understand.
I need the output from the HTTP request.
0
 
QlemoC++ DeveloperCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
flowerbloomAuthor Commented:
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
 
QlemoC++ DeveloperCommented:
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
 
flowerbloomAuthor Commented:
I added an extra ENTER and it does not help.  same results.
0
 
RobOwner (Aidellio)Commented:
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
 
RobOwner (Aidellio)Commented:
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
 
RobOwner (Aidellio)Commented:
so all your bat file needs to be:

--- run_curl.bat
%curl_dir%curl.exe 192.168.x.y 80 > curl_log.html
0
 
flowerbloomAuthor Commented:
Works great! Thanks!
0
 
flowerbloomAuthor Commented:
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!

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now