Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Telnet HTTP stuck in batch

Posted on 2013-12-10
12
Medium Priority
?
522 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 71

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 71

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 71

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 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview
Suggested Courses

886 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