Solved

Telnet HTTP stuck in batch

Posted on 2013-12-10
12
501 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 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
???
I don't understand.
I need the output from the HTTP request.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
 
LVL 1

Author Comment

by:flowerbloom
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:flowerbloom
Comment Utility
I added an extra ENTER and it does not help.  same results.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Works great! Thanks!
0
 
LVL 1

Author Closing Comment

by:flowerbloom
Comment Utility
It works!
0

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.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

11 Experts available now in Live!

Get 1:1 Help Now