Results 1 to 11 of 11

Thread: Detect country of origin

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Detect country of origin

    Guys

    What's the most accurate way of determining which country a visitor to your website is in? I'm currently using HTTP_ACCEPT_LANGUAGE but doesn't this just test the language settings? Ok, this should be set to the correct country but it isn't foolproof, is it?
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Detect country of origin

    This will give you a country code.

    VB Code:
    1. On Error Resume Next
    2.  
    3. Const wbemFlagReturnImmediately = &h10
    4. Const wbemFlagForwardOnly = &h20
    5.  
    6. arrComputers = Array("MYMACHINENAME")
    7. For Each strComputer In arrComputers
    8.    WScript.Echo
    9.    WScript.Echo "=========================================="
    10.    WScript.Echo "Computer: " & strComputer
    11.    WScript.Echo "=========================================="
    12.  
    13.    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    14.    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
    15.                                           wbemFlagReturnImmediately + wbemFlagForwardOnly)
    16.  
    17.    For Each objItem In colItems
    18.       WScript.Echo "BootDevice: " & objItem.BootDevice
    19.       WScript.Echo "BuildNumber: " & objItem.BuildNumber
    20.       WScript.Echo "BuildType: " & objItem.BuildType
    21.       WScript.Echo "Caption: " & objItem.Caption
    22.       WScript.Echo "CodeSet: " & objItem.CodeSet
    23.       WScript.Echo "CountryCode: " & objItem.CountryCode
    24.       WScript.Echo "CreationClassName: " & objItem.CreationClassName
    25.       WScript.Echo "CSCreationClassName: " & objItem.CSCreationClassName
    26.       WScript.Echo "CSDVersion: " & objItem.CSDVersion
    27.       WScript.Echo "CSName: " & objItem.CSName
    28.       WScript.Echo "CurrentTimeZone: " & objItem.CurrentTimeZone
    29.       WScript.Echo "DataExecutionPrevention_32BitApplications: " & objItem.DataExecutionPrevention_32BitApplications
    30.       WScript.Echo "DataExecutionPrevention_Available: " & objItem.DataExecutionPrevention_Available
    31.       WScript.Echo "DataExecutionPrevention_Drivers: " & objItem.DataExecutionPrevention_Drivers
    32.       WScript.Echo "DataExecutionPrevention_SupportPolicy: " & objItem.DataExecutionPrevention_SupportPolicy
    33.       WScript.Echo "Debug: " & objItem.Debug
    34.       WScript.Echo "Description: " & objItem.Description
    35.       WScript.Echo "Distributed: " & objItem.Distributed
    36.       WScript.Echo "EncryptionLevel: " & objItem.EncryptionLevel
    37.       WScript.Echo "ForegroundApplicationBoost: " & objItem.ForegroundApplicationBoost
    38.       WScript.Echo "FreePhysicalMemory: " & objItem.FreePhysicalMemory
    39.       WScript.Echo "FreeSpaceInPagingFiles: " & objItem.FreeSpaceInPagingFiles
    40.       WScript.Echo "FreeVirtualMemory: " & objItem.FreeVirtualMemory
    41.       WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
    42.       WScript.Echo "LargeSystemCache: " & objItem.LargeSystemCache
    43.       WScript.Echo "LastBootUpTime: " & WMIDateStringToDate(objItem.LastBootUpTime)
    44.       WScript.Echo "LocalDateTime: " & WMIDateStringToDate(objItem.LocalDateTime)
    45.       WScript.Echo "Locale: " & objItem.Locale
    46.       WScript.Echo "Manufacturer: " & objItem.Manufacturer
    47.       WScript.Echo "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses
    48.       WScript.Echo "MaxProcessMemorySize: " & objItem.MaxProcessMemorySize
    49.       WScript.Echo "Name: " & objItem.Name
    50.       WScript.Echo "NumberOfLicensedUsers: " & objItem.NumberOfLicensedUsers
    51.       WScript.Echo "NumberOfProcesses: " & objItem.NumberOfProcesses
    52.       WScript.Echo "NumberOfUsers: " & objItem.NumberOfUsers
    53.       WScript.Echo "Organization: " & objItem.Organization
    54.       WScript.Echo "OSLanguage: " & objItem.OSLanguage
    55.       WScript.Echo "OSProductSuite: " & objItem.OSProductSuite
    56.       WScript.Echo "OSType: " & objItem.OSType
    57.       WScript.Echo "OtherTypeDescription: " & objItem.OtherTypeDescription
    58.       WScript.Echo "PlusProductID: " & objItem.PlusProductID
    59.       WScript.Echo "PlusVersionNumber: " & objItem.PlusVersionNumber
    60.       WScript.Echo "Primary: " & objItem.Primary
    61.       WScript.Echo "ProductType: " & objItem.ProductType
    62.       WScript.Echo "QuantumLength: " & objItem.QuantumLength
    63.       WScript.Echo "QuantumType: " & objItem.QuantumType
    64.       WScript.Echo "RegisteredUser: " & objItem.RegisteredUser
    65.       WScript.Echo "SerialNumber: " & objItem.SerialNumber
    66.       WScript.Echo "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
    67.       WScript.Echo "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion
    68.       WScript.Echo "SizeStoredInPagingFiles: " & objItem.SizeStoredInPagingFiles
    69.       WScript.Echo "Status: " & objItem.Status
    70.       WScript.Echo "SuiteMask: " & objItem.SuiteMask
    71.       WScript.Echo "SystemDevice: " & objItem.SystemDevice
    72.       WScript.Echo "SystemDirectory: " & objItem.SystemDirectory
    73.       WScript.Echo "SystemDrive: " & objItem.SystemDrive
    74.       WScript.Echo "TotalSwapSpaceSize: " & objItem.TotalSwapSpaceSize
    75.       WScript.Echo "TotalVirtualMemorySize: " & objItem.TotalVirtualMemorySize
    76.       WScript.Echo "TotalVisibleMemorySize: " & objItem.TotalVisibleMemorySize
    77.       WScript.Echo "Version: " & objItem.Version
    78.       WScript.Echo "WindowsDirectory: " & objItem.WindowsDirectory
    79.       WScript.Echo
    80.    Next
    81. Next
    82.  
    83.  
    84. Function WMIDateStringToDate(dtmDate)
    85. WScript.Echo dtm:
    86.     WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    87.     Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    88.     & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    89. End Function
    Last edited by dglienna; May 14th, 2005 at 01:43 PM.

  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Detect country of origin

    I'm using asp/vbsript. What does wscript.echo do?
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Detect country of origin

    Writes to the screen, but you could use Response.Write instead.

  5. #5

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Detect country of origin

    Yeah, I figured that out. I can't run the code that you gave me, or any variations of it (been doing a bit of reading on WSH). I get an error which appears to point at permissions on my machine but I have admin rights for this machine. This won't be any good for deploying to a live website.

    The error I get is this:

    VB Code:
    1. Error Type:
    2. (0x80041003)
    3. /countrytest.asp, line 95
    Last edited by thebloke; May 16th, 2005 at 05:02 AM. Reason: additional comment
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  6. #6
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Detect country of origin

    I could be wrong but I don't think you can execute that code from a website - due to permissions. Client-side code has strict limitations when running in a browser - you certainly can't get all those details about a website visitors machine for privacy reasons.

    Server-side you could use Request.ServerVariables("REMOTE_ADDR") to return the visitors IP address and then use a third party service to find the location of the visitor. Please note this is not completely accurate though - I show up as London, UK but this is where my ISP is based - I'm in Birmingham.

    It depends if this information needs to be 100% accurate - if you only want it for localisation purposes this is quite good enough.

    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  7. #7

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Detect country of origin

    Thanks DJ, I was kind of coming to that conclusion although I know nowt about WSH.

    I'm currently using request.servervariables("HTTP_ACCEPT_LANGUAGE") which works fine as long as the user has the correct language settings on their browser but if I change my settings to en-us then the code thinks that I'm in the US.

    I've seen some third party gadgets (countryhawk) but I was hoping that I could so something with a standard bit of code.

    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  8. #8
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Detect country of origin

    Quote Originally Posted by thebloke
    Thanks DJ, I was kind of coming to that conclusion although I know nowt about WSH.

    I'm currently using request.servervariables("HTTP_ACCEPT_LANGUAGE") which works fine as long as the user has the correct language settings on their browser but if I change my settings to en-us then the code thinks that I'm in the US.

    I've seen some third party gadgets (countryhawk) but I was hoping that I could so something with a standard bit of code.

    Unfortunately there is no standard way of determining The origin of user. I have used a 3rd party free tool, which maps the country name from the IP adress. Dont know how accurate it is but it fullfilled my requirement.

    If you are interested then search for GeoIP and you should find it..
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  9. #9

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Detect country of origin

    Thanks Danial. I'm not sure that this is any more certain than the current method I'm using ("HTTP_ACCEPT_LANGUAGE") - I'm only trying to distinguish visitors from the US from the UK.

    Thanks anyway.
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  10. #10
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Detect country of origin

    Why not ask them the first time they visit the site and then store the result in a cookie? More low tec I know but it'll do the job.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  11. #11

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved Re: Detect country of origin

    Good point. It's not the ideal solution but it might just work. I like it!
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width