[ Go to April 1997 Table of Contents ]|
Take Stock of Telnet
Automate Web searches using command-line and agent technology for NT.
Windows NT's telnet capabilities are a lot like Rodney Dangerfield: They get no respect. That's not fair, at least in the case of telnet, a command-line application that's here to stay.
Long ago, when the Internet was called ARPAnet (Advanced Research Projects Agency Network), telnet was the default way for users to communicate. Using telnet (a network terminal), you logged in to a host system, which would present you with text-based information. Today, of course, most such information is available graphically over the World Wide Web.
That doesn't mean NT's telnet support is now useless. I use it myself to access CompuServe from the Internet, rather than fire up a special application and dial in to CompuServe separately. Indeed, I find that telnet is one of the features I miss on my Windows CE-based hand-held computer.
There are other uses for telnet. In fact, some Internet services are still telnet-only. For instance, the Federal Aviation Administration subcontracts with GTE to provide online weather information for private pilots. To get it, you must telnet DUAT.GTEFSD.COM.
Want to try telnet for yourself? Here's how: Fire up telnet in NT Workstation by selecting Start/Run and typing telnet. Select Connect/Remote System, type http://www.winmag.com as the host name and 80 as the port, and then click on the Connect button. Nothing will happen for a second, then the title bar will change to read www.winmag.com (if you get a No Connection message, check your Internet connection and try again)
Now, type GET /news/ and press enter. (Be sure to leave a space between the T and /.) Screen after screen of text will blast by, followed by a Connection to Host Lost message (when you click on the OK button, the text will disappear). Here's what that first text that goes by says:
HTTP/1.0 200 OKDate: Tue, 14 Jan 1997 00:29:57
GMTServer: WebSitePro/1.1g (S/N WPO-1B79)Accept-ranges: bytesContent-type:
text/htmlContent-length: 0 <HTML> <HEAD> <TITLE>WinMag News </TITLE> </HEAD>...
What you're looking at isn't gibberish; it's the raw material of a Web page, specifically: http://www.winmag.com/news/.
Putting telnet to work
Now that I've given you a quick overview of telnet, let's do something useful with it. For instance, I'd like to use telnet to automatically gather and filter information from the Web. To do this, I figure I'll need a scriptable Web browser (one that can be programmed). I'll also need to define a simple automatic filter that works something like this:
1. Read the first Web address from a list of the addresses I'm interested in.
2. Browse the Web page associated with that address.
3. Capture the HTML from that page and save it in a file.
4. Compare the file to an earlier version; if they're different, mark the page as one I need to read.
5. Continue for all the other addresses in the list.
Once I have my filter working, I'd like to set it to run automatically-at 4 a.m. daily, for example. That way, when I wake up, I'll only need to look at the marked pages. That's a pretty simple program, but how would I write it?
Both Netscape Navigator 2.0 and Microsoft Internet Explorer 3.0 are supposed to be scriptable, via OLE-but that's a pain in the neck, and neither comes with Visual Basic for Applications. I could create the filter using Visual Basic, but do I really want to dig through the complicated object structure, methods and forms involved in programming Navigator and Internet Explorer? After all, to make the filter work, all I really need is a way to capture the HTML from a page.
Which brings me back to the command line and telnet. If Microsoft had implemented NT telnet as a command-line app that accepted the Internet address, port number and a string of text to send as arguments, I could capture the text like this:
telnet www.winmag.com 80
>"GET /news/" news.htm
>The tells a command-line app (in this case, our hypothetical command-line telnet) to redirect its output from the screen to a file called NEWS.HTM. That's one of the things that makes command-line programs so useful-the ability to easily redirect both input and output, run one program right after another and schedule programs for automatic execution.
Unfortunately, NT telnet offers no way to capture the output, short of using Clipboard cut-and-paste. Even that won't work if you telnet to a Web site, since the connection's broken as soon as the text is sent, and the text disappears before you can copy it. (And in any case, there is no way to copy it automatically.)
In other words, NT's built-in telnet can't support the five-step process I described earlier. But don't lose faith. There is a workaround.
A proper solution
What I need is a proper text-mode command-line telnet for NT, and after searching fruitlessly for one, I finally decided to write it myself. You can download it from a link on my personal Web page (http://www.winmag.com/people/jruley). Using my telnet applet in conjunction with WebAgent, a Web-scanning program I wrote, you can automatically fetch and filter information from the Web.
WebAgent is a pretty simplistic piece of software (available at http://www.winmag.com/people/jruley/webagent) that filters three informative sites that happen to interest me (http://www.microsoft.com/corpinfo/, http://www.techweb.com/wire/,and of course, http://www.winmag.com/news/). If you don't mind experimenting a bit, you can customize WebAgent to add pages that you're interested in.
Please bear in mind that WebAgent is intended mainly as an example batch file-it's hardly up to shrink-wrap standards. (Though I'm sure some readers would argue shrink-wrap software isn't up to snuff, either.) Customizing WebAgent will require you to edit the batch file source. If that doesn't put you off, great! You'll have a lot of fun and maybe learn something in the process.
If you don't want to do all that work, I've provided links on that page to a number of more polished alternatives.
Book of the month
I intentionally glossed over the minor issue of exactly how I wrote my command-line telnet. If you're not afraid of a little C code, you can download the source from http://www.winmag.com/people/jruley/telnet. It's pretty basic Winsock programming-but while writing it, I found one book indispensable: Win32 Network Programming by Ralph Davis (Addison-Wesley, 1996). If you have trouble understanding my telnet source, Chapter 9 of Davis' book will be a great help to you. It certainly helped me.
Incidentally, the code I wrote uses the old Winsock 1.1 API rather than the newer 2.0 version. Why? Because Windows CE supports Winsock 1.1-so maybe I won't be missing telnet on my palmtop too much longer!
It's obvious Microsoft has been missing the boat on command-line applications and batch files. Still, somewhere in the NT group there are people who know better. How can I tell? Start a command prompt on NT 4.0 and type HELP SET. On earlier versions of NT, you'd get just seven terse lines of explanation about how to set environment variables. On NT 4.0, you will see several screens' worth of information on how SET has been enhanced to, among other things, allow arithmetic and logical operations in batch files. Check NT online help for more enhancements. And if you have the NT Resource Kit, be sure to experiment with KIXSTART; it's an enhanced command processor for NT with many advanced features. So my Brilliant Award of the Month goes to the unsung Microsoft programmer (or programmers) who worked on those enhancements.
The Bogus Award
As for the Bogus Award of the Month-that's easy: Windows 95. To the list of things NT users love to hate about Microsoft's other operating system, add this: Win95 lacks the RASDIAL command, so my WebAgent batch file can't dial the phone on a Windows 95 system. So much for compatibility across both operating systems.
Senior technical editor John D. Ruley is WINDOWS Magazine's resident NT guru, and principal author of Networking Windows NT 4.0, Third Edition (John Wiley & Sons, 1996). You can reach John at http://www.winmag.com/ew or at the e-mail addresses here.