homepage Welcome to WebmasterWorld Guest from 54.166.105.24
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Current IP addresses viewing website.
Maybe using a Global.asa script...
isaaclloyd




msg:950610
 6:35 pm on Oct 7, 2005 (gmt 0)

I am wondering if there is a way to generate a list of IP addresses currently viewing the website instead of a # of connections. Here is the code I am currently using to view how many people are viewing the site:

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub

Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 5
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub

Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub

</SCRIPT>

Any comments or suggestions would greatly be appreciated.

~Isaac~

 

fish_eye




msg:950611
 3:03 am on Oct 10, 2005 (gmt 0)

I'm no guru but:
Dim ClientIP As String = [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpRequestClassUserHostAddressTopic.asp]Request.UserHostAddress[/url]
is used in an application I've inherited.

This is used in the application that is being run by the user. I guess you could log this with a date and time and then analyse later.

txbakers




msg:950612
 3:17 am on Oct 10, 2005 (gmt 0)

I have the very thing:


<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">
</object>

<script language="VBScript" runat="Server">
' The first thing you should notice is the top line.
' It creates an application scoped recordset object
' named rstActiveUsers that I'll use to store all
' our user information.
'
' Note: I've wrapped it for readability

Sub Application_OnStart()
' Selected constants from adovbs.inc
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7

' Here I set up in memory active user recordset
' by adding the fields I want to it and defining
' their data types.
rstActiveUsers.Fields.Append "id", adInteger
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate

' Next I open our recordset so that we can use it.
' That basically gets everything ready for our
' first user.
rstActiveUsers.Open
End Sub

Sub Session_OnStart()
' Set session timeout to 20 minutes
Session.Timeout = 20

' Set a session start time. This is pretty pointless,
' but it does ensure that we start a session and
' assign the user a session id and it can help
' troubleshooting if we ever need it.
Session("Start") = Now()

' Move to the end so records are added in order.
' Again not of any real importance, but it keeps our
' user table nice and orderly.
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast

' Add a record and insert users data. I'm just
' storing some basic info, but naturally you're free
' to store whatever you want.
rstActiveUsers.AddNew

rstActiveUsers.Fields("id").Value = _
Session.SessionID

rstActiveUsers.Fields("ip").Value = _
Request.ServerVariables("REMOTE_HOST")

rstActiveUsers.Fields("browser").Value = _
Request.ServerVariables("HTTP_USER_AGENT")

rstActiveUsers.Fields("started").Value = _
Now()

rstActiveUsers.Update

' Now that we've got the information, all that's
' left is to display it. See test_page.asp for a
' demo. It includes the pages show_count.asp and
' show_users.asp which can also be used
' individually if desired.
End Sub

Sub Session_OnEnd()
' Selected constants from adovbs.inc
Const adAffectCurrent = 1

' Start at the first record
rstActiveUsers.MoveFirst

' Check each record for the SessionID
Do While Not rstActiveUsers.EOF
' Do conversion to Long to be sure we're
' comparing the same data type.
If CLng(rstActiveUsers.Fields("id").Value) = _
CLng(Session.SessionID) Then
rstActiveUsers.Delete adAffectCurrent
End If

rstActiveUsers.MoveNext
Loop

rstActiveUsers.Update
End Sub

Sub Application_OnEnd()
' Not like it really matters, but for the sake of
' good coding practice I close the recordset when
' our application is shutting down.
rstActiveUsers.Close
End Sub
</script>

this creates a recordset with a list of all the active sessions by IP address.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved