Code:
'******************************************
'*** Get Web Browser Details *****
'******************************************
Private Function BrowserType()
Dim strUserAgent 'Holds info on the users browser and os
Dim strBrowserUserType 'Holds the users browser type
'Get the users HTTP user agent (web browser)
strUserAgent = Request.ServerVariables("HTTP_USER_AGENT")
'Get the uesrs web browser
'Opera
If InStr(1, strUserAgent, "Opera 1", 1) > 0 Then
strBrowserUserType = "Opera 1"
ElseIf InStr(1, strUserAgent, "Opera 2", 1) > 0 Then
strBrowserUserType = "Opera 2"
ElseIf InStr(1, strUserAgent, "Opera 3", 1) > 0 Then
strBrowserUserType = "Opera 3"
ElseIf InStr(1, strUserAgent, "Opera 4", 1) > 0 Then
strBrowserUserType = "Opera 4"
ElseIf InStr(1, strUserAgent, "Opera 5", 1) > 0 Then
strBrowserUserType = "Opera 5"
ElseIf InStr(1, strUserAgent, "Opera 6", 1) > 0 Then
strBrowserUserType = "Opera 6"
ElseIf InStr(1, strUserAgent, "Opera 7", 1) > 0 Then
strBrowserUserType = "Opera 7"
ElseIf InStr(1, strUserAgent, "Opera 8", 1) > 0 Then
strBrowserUserType = "Opera 8"
ElseIf InStr(1, strUserAgent, "Opera", 1) > 0 Then
strBrowserUserType = "Opera"
'AOL
ElseIf inStr(1, strUserAgent, "AOL 3", 1) > 0 Then
strBrowserUserType = "AOL 3"
ElseIf inStr(1, strUserAgent, "AOL 4", 1) > 0 Then
strBrowserUserType = "AOL 4"
ElseIf inStr(1, strUserAgent, "AOL 5", 1) > 0 Then
strBrowserUserType = "AOL 5"
ElseIf inStr(1, strUserAgent, "AOL 6", 1) > 0 Then
strBrowserUserType = "AOL 6"
ElseIf inStr(1, strUserAgent, "AOL 7", 1) > 0 Then
strBrowserUserType = "AOL 7"
ElseIf inStr(1, strUserAgent, "AOL 8", 1) > 0 Then
strBrowserUserType = "AOL 8"
ElseIf inStr(1, strUserAgent, "AOL 9", 1) > 0 Then
strBrowserUserType = "AOL 9"
ElseIf inStr(1, strUserAgent, "AOL", 1) > 0 Then
strBrowserUserType = "AOL"
'Konqueror
ElseIf inStr(1, strUserAgent, "Konqueror", 1) > 0 Then
strBrowserUserType = "Konqueror"
'EudoraWeb
ElseIf inStr(1, strUserAgent, "EudoraWeb", 1) > 0 Then
strBrowserUserType = "EudoraWeb"
'Dreamcast
ElseIf inStr(1, strUserAgent, "Dreamcast", 1) > 0 Then
strBrowserUserType = "Dreamcast"
'Safari
ElseIf inStr(1, strUserAgent, "Safari", 1) > 0 Then
strBrowserUserType = "Safari"
'Lynx
ElseIf inStr(1, strUserAgent, "Lynx", 1) > 0 Then
strBrowserUserType = "Lynx"
'ICE
ElseIf inStr(1, strUserAgent, "ICE", 1) > 0 Then
strBrowserUserType = "ICE"
'iCab
ElseIf inStr(1, strUserAgent, "iCab", 1) > 0 Then
strBrowserUserType = "iCab"
'HotJava
ElseIf inStr(1, strUserAgent, "Sun", 1) > 0 AND inStr(1, strUserAgent, "Mozilla/3", 1) > 0 Then
strBrowserUserType = "HotJava"
'Galeon
ElseIf inStr(1, strUserAgent, "Galeon", 1) > 0 Then
strBrowserUserType = "Galeon"
'Epiphany
ElseIf inStr(1, strUserAgent, "Epiphany", 1) > 0 Then
strBrowserUserType = "Epiphany"
'DocZilla
ElseIf inStr(1, strUserAgent, "DocZilla", 1) > 0 Then
strBrowserUserType = "DocZilla"
'Camino
ElseIf inStr(1, strUserAgent, "Chimera", 1) > 0 OR inStr(1, strUserAgent, "Camino", 1) > 0 Then
strBrowserUserType = "Camino"
'Dillo
ElseIf inStr(1, strUserAgent, "Dillo", 1) > 0 Then
strBrowserUserType = "Dillo"
'amaya
ElseIf inStr(1, strUserAgent, "amaya", 1) > 0 Then
strBrowserUserType = "Amaya"
'NetCaptor
ElseIf inStr(1, strUserAgent, "NetCaptor", 1) > 0 Then
strBrowserUserType = "NetCaptor"
'Internet Explorer
ElseIf inStr(1, strUserAgent, "MSIE 7", 1) > 0 Then
strBrowserUserType = "Microsoft IE 7"
ElseIf inStr(1, strUserAgent, "MSIE 6", 1) > 0 Then
strBrowserUserType = "Microsoft IE 6"
ElseIf inStr(1, strUserAgent, "MSIE 5", 1) > 0 Then
strBrowserUserType = "Microsoft IE 5"
ElseIf inStr(1, strUserAgent, "MSIE 4", 1) > 0 Then
strBrowserUserType = "Microsoft IE 4"
ElseIf inStr(1, strUserAgent, "MSIE 3", 1) > 0 Then
strBrowserUserType = "Microsoft IE 3"
ElseIf inStr(1, strUserAgent, "MSIE 2", 1) > 0 Then
strBrowserUserType = "Microsoft IE 2"
ElseIf inStr(1, strUserAgent, "MSIE 1", 1) > 0 Then
strBrowserUserType = "Microsoft IE 1"
ElseIf inStr(1, strUserAgent, "MSPIE 1", 1) > 0 Then
strBrowserUserType = "Pocket IE 1"
ElseIf inStr(1, strUserAgent, "MSPIE 1", 1) > 0 Then
strBrowserUserType = "Pocket IE 2"
ElseIf inStr(1, strUserAgent, "Gecko", 1) > 0 AND inStr(1, strUserAgent, "Firebird", 1) > 0 Then
strBrowserUserType = "Mozilla Firebird"
ElseIf inStr(1, strUserAgent, "Gecko", 1) > 0 AND inStr(1, strUserAgent, "rv:2", 1) > 0 AND inStr(1, strUserAgent, "Netscape", 1) = 0 Then
strBrowserUserType = "Mozilla 2"
ElseIf inStr(1, strUserAgent, "Gecko", 1) > 0 AND inStr(1, strUserAgent, "rv:1", 1) > 0 AND inStr(1, strUserAgent, "Netscape", 1) = 0 Then
strBrowserUserType = "Mozilla 1"
ElseIf inStr(1, strUserAgent, "Gecko", 1) > 0 AND inStr(1, strUserAgent, "rv:0", 1) > 0 AND inStr(1, strUserAgent, "Netscape", 1) = 0 Then
strBrowserUserType = "Mozilla"
ElseIf inStr(1, strUserAgent, "Netscape/8", 1) > 0 Then
strBrowserUserType = "Netscape 8"
ElseIf inStr(1, strUserAgent, "Netscape/7", 1) > 0 Then
strBrowserUserType = "Netscape 7"
ElseIf inStr(1, strUserAgent, "Netscape6", 1) > 0 Then
strBrowserUserType = "Netscape 6"
ElseIf inStr(1, strUserAgent, "Mozilla/4", 1) > 0 Then
strBrowserUserType = "Netscape 4"
ElseIf inStr(1, strUserAgent, "Mozilla/3", 1) > 0 Then
strBrowserUserType = "Netscape 3"
ElseIf inStr(1, strUserAgent, "Mozilla/2", 1) > 0 Then
strBrowserUserType = "Netscape 2"
ElseIf inStr(1, strUserAgent, "Mozilla/1", 1) > 0 Then
strBrowserUserType = "Netscape 1"
'//---------------------------------------------------
'// SEARCH BOTS
'//---------------------------------------------------
'LookSmart search engine robot
ElseIf inStr(1, strUserAgent, "ZyBorg", 1) > 0 Then
strBrowserUserType = "LookSmart"
blnSpider = True
'Googlebot search engine robot
ElseIf inStr(1, strUserAgent, "Googlebot", 1) > 0 Then
strBrowserUserType = "Googlebot"
blnSpider = True
'MSN search engine robot
ElseIf inStr(1, strUserAgent, "msnbot", 1) > 0 Then
strBrowserUserType = "MSN"
blnSpider = True
'inktomi search engine robot
ElseIf inStr(1, strUserAgent, "slurp", 1) > 0 Then
strBrowserUserType = "Inktomi"
blnSpider = True
'AltaVista search engine robot
ElseIf inStr(1, strUserAgent, "Scooter", 1) > 0 Then
strBrowserUserType = "AltaVista"
blnSpider = True
'DMOZ search engine robot
ElseIf inStr(1, strUserAgent, "Robozilla", 1) > 0 Then
strBrowserUserType = "DMOZ"
blnSpider = True
'Ask Jeeves search engine robot
ElseIf inStr(1, strUserAgent, "Ask Jeeves", 1) > 0 OR inStr(1, strUserAgent, "Ask+Jeeves", 1) > 0 Then
strBrowserUserType = "Ask Jeeves"
blnSpider = True
'Lycos search engine robot
ElseIf inStr(1, strUserAgent, "lycos", 1) > 0 Then
strBrowserUserType = "Lycos"
blnSpider = True
'Excite search engine robot
ElseIf inStr(1, strUserAgent, "ArchitextSpider", 1) > 0 Then
strBrowserUserType = "Excite"
blnSpider = True
'Northernlight search engine robot
ElseIf inStr(1, strUserAgent, "Gulliver", 1) > 0 Then
strBrowserUserType = "Northernlight"
blnSpider = True
'AllTheWeb search engine robot
ElseIf inStr(1, strUserAgent, "crawler@fast", 1) > 0 Then
strBrowserUserType = "AllTheWeb"
blnSpider = True
'Turnitin search engine robot
ElseIf inStr(1, strUserAgent, "TurnitinBot", 1) > 0 Then
strBrowserUserType = "Turnitin"
blnSpider = True
'InternetSeer search engine robot
ElseIf inStr(1, strUserAgent, "internetseer", 1) > 0 Then
strBrowserUserType = "InternetSeer"
blnSpider = True
'NameProtect Inc. search engine robot
ElseIf inStr(1, strUserAgent, "nameprotect", 1) > 0 Then
strBrowserUserType = "NameProtect"
blnSpider = True
'PhpDig search engine robot
ElseIf inStr(1, strUserAgent, "PhpDig", 1) > 0 Then
strBrowserUserType = "PhpDig"
blnSpider = True
'Rambler search engine robot
ElseIf inStr(1, strUserAgent, "StackRambler", 1) > 0 Then
strBrowserUserType = "Rambler"
blnSpider = True
'UbiCrawler search engine robot
ElseIf inStr(1, strUserAgent, "UbiCrawler", 1) > 0 Then
strBrowserUserType = "UbiCrawler"
blnSpider = True
'entireweb search engine robot
ElseIf inStr(1, strUserAgent, "Speedy+Spider", 1) > 0 Then
strBrowserUserType = "entireweb"
blnSpider = True
'Alexa.com search engine robot
ElseIf inStr(1, strUserAgent, "ia_archiver", 1) > 0 Then
strBrowserUserType = "Alexa"
blnSpider = True
'Arianna/Libero search engine robot
ElseIf inStr(1, strUserAgent, "arianna.libero.it", 1) > 0 Then
strBrowserUserType = "Arianna/Libero"
blnSpider = True
'//---------------------------------------------------
'Else unknown or robot
Else
strBrowserUserType = "Unknown_browser"
End If
'Return function
BrowserType = strBrowserUserType
End Function
'******************************************
'*** Get OS Type *****
'******************************************
Private Function OSType ()
Dim strUserAgent 'Holds info on the users browser and os
Dim strOS 'Holds the users OS
'Get the users HTTP user agent (web browser)
strUserAgent = Request.ServerVariables("HTTP_USER_AGENT")
'Get users OS
'Windows
If inStr(1, strUserAgent, "Windows 2003", 1) > 0 Or inStr(1, strUserAgent, "NT 5.2", 1) > 0 Then
strOS = "Windows 2003"
ElseIf inStr(1, strUserAgent, "Windows XP", 1) > 0 Or inStr(1, strUserAgent, "NT 5.1", 1) > 0 Then
strOS = "Windows XP"
ElseIf inStr(1, strUserAgent, "Windows 2000", 1) > 0 Or inStr(1, strUserAgent, "NT 5", 1) > 0 Then
strOS = "Windows 2000"
ElseIf inStr(1, strUserAgent, "Windows NT", 1) > 0 Or inStr(1, strUserAgent, "WinNT", 1) > 0 Then
strOS = "Windows NT 4"
ElseIf inStr(1, strUserAgent, "Windows 95", 1) > 0 Or inStr(1, strUserAgent, "Win95", 1) > 0 Then
strOS = "Windows 95"
ElseIf inStr(1, strUserAgent, "Windows ME", 1) > 0 Or inStr(1, strUserAgent, "Win 9x 4.90", 1) > 0 Then
strOS = "Windows ME"
ElseIf inStr(1, strUserAgent, "Windows 98", 1) > 0 Or inStr(1, strUserAgent, "Win98", 1) > 0 Then
strOS = "Windows 98"
ElseIf Instr(1, strUserAgent, "Windows 3.1", 1) > 0 or Instr(1, strUserAgent, "Win16", 1) > 0 Then
strOS = "Windows 3.x"
ElseIf Instr(1, strUserAgent, "Windows CE", 1) > 0 Then
strOS = "Windows CE"
ElseIf inStr(1, strUserAgent, "PalmOS", 1) > 0 Then
strOS = "Palm OS"
ElseIf inStr(1, strUserAgent, "Elaine", 1) > 0 Then
strOS = "PalmPilot"
ElseIf inStr(1, strUserAgent, "Nokia", 1) > 0 Then
strOS = "Nokia"
ElseIf inStr(1, strUserAgent, "Linux", 1) > 0 Then
strOS = "Linux"
ElseIf inStr(1, strUserAgent, "Amiga", 1) > 0 Then
strOS = "Amiga"
ElseIf inStr(1, strUserAgent, "Solaris", 1) > 0 Then
strOS = "Solaris"
ElseIf inStr(1, strUserAgent, "SunOS", 1) > 0 Then
strOS = "Sun OS"
ElseIf inStr(1, strUserAgent, "BSD", 1) > 0 or inStr(1, strUserAgent, "FreeBSD", 1) > 0 Then
strOS = "Free BSD"
ElseIf inStr(1, strUserAgent, "Unix", 1) > 0 OR inStr(1, strUserAgent, "X11", 1) > 0 Then
strOS = "Unix"
ElseIf inStr(1, strUserAgent, "AOLTV", 1) > 0 OR inStr(1, strUserAgent, "AOL_TV", 1) > 0 Then
strOS = "AOL TV"
ElseIf inStr(1, strUserAgent, "WebTV", 1) > 0 Then
strOS = "Web TV"
ElseIf inStr(1, strUserAgent, "Mac OS X", 1) > 0 Then
strOS = "Mac OS X"
ElseIf inStr(1, strUserAgent, "Mac_PowerPC", 1) > 0 or Instr(1, strUserAgent, "PPC", 1) > 0 Then
strOS = "Mac PowerPC"
ElseIf (inStr(1, strUserAgent, "6800", 1) > 0 OR inStr(1, strUserAgent, "68k", 1) > 0) AND inStr(1, strUserAgent, "Mac", 1) > 0 Then
strOS = "Mac 68k"
ElseIf inStr(1, strUserAgent, "Mac", 1) > 0 or inStr(1, strUserAgent, "apple", 1) > 0 Then
strOS = "Macintosh"
ElseIf inStr(1, strUserAgent, "OS/2", 1) > 0 Then
strOS = "OS/2"
ElseIf inStr(1, strUserAgent, "Googlebot", 1) > 0 OR inStr(1, strUserAgent, "ZyBorg", 1) > 0 OR inStr(1, strUserAgent, "slurp", 1) > 0 OR inStr(1, strUserAgent, "Scooter", 1) > 0 OR inStr(1, strUserAgent, "Robozilla", 1) > 0 OR inStr(1, strUserAgent, "Ask Jeeves", 1) > 0 OR inStr(1, strUserAgent, "Ask+Jeeves", 1) > 0 OR inStr(1, strUserAgent, "lycos", 1) > 0 OR inStr(1, strUserAgent, "ArchitextSpider", 1) > 0 OR inStr(1, strUserAgent, "Gulliver", 1) > 0 OR inStr(1, strUserAgent, "crawler@fast", 1) > 0 Then
strOS = "Search Robot"
ElseIf inStr(1, strUserAgent, "TurnitinBot", 1) > 0 OR inStr(1, strUserAgent, "internetseer", 1) > 0 OR inStr(1, strUserAgent, "nameprotect", 1) > 0 OR inStr(1, strUserAgent, "PhpDig", 1) > 0 OR inStr(1, strUserAgent, "StackRambler", 1) > 0 OR inStr(1, strUserAgent, "UbiCrawler", 1) > 0 OR inStr(1, strUserAgent, "Speedy+Spider", 1) > 0 OR inStr(1, strUserAgent, "ia_archiver", 1) > 0 OR inStr(1, strUserAgent, "msnbot", 1) > 0 OR inStr(1, strUserAgent, "arianna.libero.it", 1) > 0 Then
strOS = "Search Robot"
Else
strOS = "Unknown_os"
End If
'Return function
OSType = strOS
End Function
'******************************************
'*** Get users IP address ***
'******************************************
Private Function getIP()
Dim strIPAddr
'If they are not going through a proxy get the IP address
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
'If they are going through multiple proxy servers only get the fisrt IP address in the list (,)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
'If they are going through multiple proxy servers only get the fisrt IP address in the list (;)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
'Get the browsers IP address not the proxy servers IP
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
'Place the IP address back into the returning function
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
Please note that this is not 100% because anyone can fool a webpage into thinking they are using another browser.