Solved

Telnet HTTP stuck in batch

Posted on 2013-12-10
12
506 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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

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.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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