Windows Scripting
  Home arrow Windows Scripting arrow Handling Live Web Content in WSH - Part 1
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Handling Live Web Content in WSH - Part 1
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2006-09-06

    Table of Contents:
  • Handling Live Web Content in WSH - Part 1
  • Processing the Response
  • A Little Error-Handling
  • The Final Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Handling Live Web Content in WSH - Part 1


    (Page 1 of 4 )

    From time to time it’s nice to be able to handle live web content with WSH. Maybe you want to capture some text from an HTML page into a text document. Or perhaps you want to check for a program update. In any case, being able to handle live web content can make for a very powerful feature.

    So let’s take a real world example.  One of the hardest things to do when scripting is determining your external, or WAN, IP address.  For those who don’t know what I’m talking about, when you connect to the internet through a local network, your local IP address is hidden and your network displays a public IP address for the rest of the world to see.  In other words, your computer has a local IP address that only your network knows.  Your network is visible to the world as a single public address so no one can see the actual computers on it.

    So why is determining your external address so hard?  Well, quite simply, Windows doesn’t provide a way to do it.  Since your external address is only visible to the public, you need something outside of your network to tell you what it is.  There are several programs available for this, but for our purposes we’re going to use a cool website.  The Current IP Address page provided by DynDns.org is a great way to do this.  Go ahead and type this address in your browser now and see what it tells you.

    http://checkip.dyndns.org

    You should get a display similar to the following showing your external IP address:

    Current IP Address: xx.xxx.xxx.xx

    This is your public IP address.  So, how can we get that into our WSH script?  To begin, let’s set the framework for our script.  We’re going to call it checkip.vbs.  The first thing that we need to do is establish a connection to the internet.  We do this by connecting to Microsoft’s XMLHttpRequest object.  This object is used for making HTTP requests.

    Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")

    Next, we use its open method to query our website.  The first parameter indicates what HTTP method we want to use.  The second is the URL that we want to request.

    Call objxmlHTTP.Open("GET", "http://checkip.dyndns.org", False)

    Once we’re connected, we use the Send() method to initiate a response from the website.

    objxmlHTTP.Send()

    The website responds by sending us an html document which we capture in a string variable using the XMLHttpRequest object’s ResponseText property.

    strHTMLText = objxmlHTTP.ResponseText

    What we have now is the entire html source of the webpage captured as a single string.  We must now break that string apart into usable pieces.  We want to strip away all of the html markup and other text so that all we have left is the IP address that it displays.  If you still have the DynDns page open in your browser, right-click the page and choose View Source and you’ll see what I mean.

    More Windows Scripting Articles
    More By Nilpo


       · I wanted this article to demonstrate some alternative uses for WSH. A lot of people...
     

    WINDOWS SCRIPTING ARTICLES

    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...
    - Working with System Processes in WSH





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway