| VBScript Scripting Techniques | > | Internet | > | Geographical Information |
| GeoIP COM (GeoIP database & COM wrapper & System Scripting Runtime) | |
|---|---|
| VBScript Code: | |
| Function GeoIP( myHost ) ' This function returns an array with the IP address, host name, city name, ' country name and country code for a specified IP address or host name. ' ' Argument: ' [string] IP address or host name ' ' Returns: ' [array of string] host name, IP address, city, country, country code ' ' Required software: ' MaxMind's GeoIP* database: http://www.maxmind.com/app/installation?city=1 ' MaxMind's GeoIP COM wrapper: https://github.com/maxmind/geoip-api-mscom ' System Scripting Runtime: http://www.netal.com/ssr.htm ' ' Written by Rob van der Woude ' http://www.robvanderwoude.com Dim objGeoIP, objDNS, objRE, strDNS, strHost, strIP Set objDNS = CreateObject( "SScripting.IPNetwork" ) Set objGeoIP = CreateObject( "GeoIPCOMEx.GeoIPEx" ) Set objRE = New RegExp ' Resolve the specified host name or IP address strDNS = objDNS.DNSLookup( myHost ) ' Check if the argument is a host name or an IP address objRE.Pattern = "ˆ[1-9][0-9]{0,2}(\.[0-9]{1,2}){3}$" If objRE.Test( myHost ) Then strIP = myHost strHost = strDNS Else strIP = strDNS strHost = myHost End If With objGeoIP ' Modify the path if you installed the GeoIP* database elsewhere .set_db_path "C:\Program Files\GeoIP\" .find_by_addr strIP GeoIP = Array( strHost, strIP, .city, .country_name, .country_code ) End With Set objDNS = Nothing Set objGeoIP = Nothing Set objRE = Nothing End Function |
|
| Requirements: | |
| Windows version: | any |
| Network: | any |
| Client software: | MaxMind's GeoIP* database and GeoIP COM wrapper, and Franz Krainer's System Scripting Runtime. |
| Script Engine: | any |
| Summarized: | Works in any Windows version. Requires MaxMind's GeoIP* database and GeoIP COM wrapper, and Franz Krainer's System Scripting Runtime. |
| [Back to the top of this page] | |
| Sample Script | |
| VBScript Code: | |
| Option Explicit WScript.Echo Join( GeoIP( "www.amazon.com" ), ", " ) WScript.Echo Join( GeoIP( "208.67.219.101" ), ", " ) |
|
| Sample output: | |
| www.amazon.com, 207.171.166.252, Seattle, United States, US www.opendns.com, 208.67.219.101, San Francisco, United States, US |
|
| [Back to the top of this page] | |
page last modified: 2025-10-16; loaded in 0.0038 seconds