Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - 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 
Mobile Linux 
App Generation ROI 
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


    Handling Live Web Content in WSH - Part 1 - The Final Code


    (Page 4 of 4 )

    Do you want to use this in other code?  This code snippet makes for a great function as well.  In the last line I used a string variable getIP for a reason. The variable you use here must match the name that you give to your function.  This tells your function to return the value of strIP when it completes.  Next, you enclose the entire snippet with the Function getIP() and End Function statements.  You can now insert this function into any code you like.  Let’s take a look at our complete code as a function.

    Function getIP()

       Set objxmlHTTP = _

           CreateObject("Microsoft.XMLHTTP")

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

       objxmlHTTP.Send()

     

       strHTMLText = objxmlHTTP.ResponseText

       Set objxmlHTTP = Nothing

     

       If strHTMLText <> "" Then

           varStart = instr(1, strHTMLText, "Current IP Address:", _

              vbTextCompare) + 19

           If varStart Then varStop = instr(varStart, strHTMLText, _

              "</body>", vbTextCompare)

           If varStart And varStop Then strIP = mid(strHTMLText, varStart, _

              varStop - varStart)

       Else

           strIP = "Unavailable"

       End If

       getIP = trim(strIP)

    End Function

    Now a call to your function would return your IP address.  Anytime you need it, simply use the following line to assign it to the string variable result.

    result = getIP()

    It’s that simple.  You now have one very powerful piece of reusable code.  With a little tweaking it could pull any information you like from whatever website you choose.

    There are many other ways you can implement this same type of script.  Perhaps you want a script that will grab the local headlines from your favorite news site.  Or maybe you just want to create a script that tests to see if your website is up and running.  There are many reasons you might want to connect to the internet and handle live web content.  Whatever your reason is, you now have the tools to do it.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





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