Logging IP Addresses
Moderator: Moderators
-
Alpinex
- Posts: 1
- Joined: 2003-02-04 20:28
Logging IP Addresses
Haven't seen it around, so I guess I'll just ask:) Anyone know of a script that will log all IP's that connect (or maybe try to connect) to a hub? This would be extremely useful for me as I run a campus hub, and am interested in knowing exactly how many people I have visiting the hub. Everyone on campus has a static ip...
thanks
thanks
-
ButterflySoul
- Posts: 210
- Joined: 2003-01-23 22:24
- Location: Nevada
Actually, it barely takes 5 minutes to write one from scratch =)
I made you one that saves the IPs in 1 logfile per day, stored in <whichever your install path of the hub software is>\ConnectLog
Enjoy ! =)
I made you one that saves the IPs in 1 logfile per day, stored in <whichever your install path of the hub software is>\ConnectLog
Enjoy ! =)
Code: Select all
Option Explicit
Dim LogAtpt, LogSucc
' ---------------------------
Sub Main
' ---------------------------
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(".\ConnectLog") Then .CreateFolder(".\ConnectLog")
LogAtpt = 1 ' **** (Connection Attempts Loging / 1=Enable / 0=Disable)
LogSucc = 1 ' **** (Connection Successful Loging / 1=Enable / 0=Disable)
End Sub
' ---------------------------
Sub AttemptedConnection (RemoteHostIP)
' ---------------------------
If LogAtpt = 0 Then Exit Sub
Call WriteLog("Attempt from " &RemoteHostIP)
End Sub
' ---------------------------
Sub NewUserConnected (curUser)
' ---------------------------
If LogSucc = 0 Then Exit Sub
Call WriteLog("Success from " &curUser.IP() &" as user " &curUser.sName)
End Sub
' ---------------------------
Sub OpConnected (curUser)
' ---------------------------
' *** This event is fired when a registered user logs in (not necessarily an OP)
If LogSucc = 0 Then Exit Sub
If Not curUser.bOperator Then Call NewUserConnected(curUser) : Exit Sub
Call WriteLog("Success from " &curUser.IP() &" as OP " &curUser.sName)
End Sub
' ---------------------------
Sub WriteLog(sEntry)
' ---------------------------
Dim fso, objLogFile
Dim sFileName
Set fso = CreateObject("Scripting.FileSystemObject")
sFileName = ".\ConnectLog\" &Year(Date)
If Month(Date) > 9 Then
sFileName = sFileName &Month(Date)
Else
sFileName = sFileName &"0" &Month(Date)
End If
If Day(Date) > 9 Then
sFileName = sFileName &Day(Date) &".log"
Else
sFileName = sFileName &"0" &Day(Date) &".log"
End If
frmHub.DoEventsForMe
Set objLogFile = fso.OpenTextFile(sFileName, 8, True)
With objLogFile
.WriteLine Time & " : " sEntry
.Close
End With
End Sub-
ButterflySoul
- Posts: 210
- Joined: 2003-01-23 22:24
- Location: Nevada
Ooops =) Small typo on top. The line :
Should be :
If Not fso.FolderExists(".\ConnectLog") Then .CreateFolder(".\ConnectLog")
Should be :
Code: Select all
If Not fso.FolderExists(".\ConnectLog") Then fso.CreateFolder(".\ConnectLog") -
Marvin
- Posts: 147
- Joined: 2003-03-06 11:56
- Location: France
Let's try this one
Code: Select all
Dim fso
Sub Main()
Set fso = CreateObject("Scripting.FileSystemObject")
end Sub
Sub AttemptedConnection (RemoteHostIP)
Dim ts
set ts = fso.OpenTextFile("IpLog.txt", 8, true)
ts.writeline cstr(RemoteHostIP)
ts.close
End Sub
-
ender
- Posts: 224
- Joined: 2003-01-03 22:47
What about this (not tested, I just wrote it here):
Code: Select all
dim ips
sub main()
Set ips = CreateObject("Scripting.Dictionary")
end sub
Sub AttemptedConnection (RemoteHostIP)
dim i
i = ips((RemoteHostIP))
if i = "" then i = 0
ips((RemoteHostIP)) = (i+1)
end Sub
sub DataArival(User,Data)
dim aip,i,text
if left(Data,1)="<" then
if instr(Data,"> showips")>0 then
aip = ips.keys
text = "Connection log:"+vbcrlf+"attempts"+vbtab+"ip"+vbcrlf
for i = 0 to ips.count -1
text = text + ips((aip(i))) & vbtab & aip(i) & vbcrlf
next
curUser.PrivateMessage "IP Logger", (text)
end if
end if
end sub-
ButterflySoul
- Posts: 210
- Joined: 2003-01-23 22:24
- Location: Nevada
Lol =) 3 versions of the script in less than 2 hours... Sounds like a promising thread =p
I quickly re-read mine, and there's another typo at the end. An "&" is missing...
Should be
This time it should work.. Sowwy
I quickly re-read mine, and there's another typo at the end. An "&" is missing...
.WriteLine Time & " : " sEntry
Should be
Code: Select all
.WriteLine Time &" : " &sEntryThis time it should work.. Sowwy
-
smitty
- Posts: 53
- Joined: 2003-03-01 19:45
guys lets not forget one thing...to read, write, and append you gotta define the constant above the Sub Main()
Code: Select all
Const ForReading = 1, ForWriting = 2, ForAppending = 8-
ButterflySoul
- Posts: 210
- Joined: 2003-01-23 22:24
- Location: Nevada
guys lets not forget one thing...to read, write, and append you gotta define the constant above the Sub Main()
If you really want to waste even more memory than what vbs already eats up, yes, you can define 3 global constants, and put "ForAppending" in the code, instead of simply "8" when you open the log file...
Personally, I try to stay away from global variables/constants, unless it really can't be avoided. It's generally better to have the scope of your variables be the one of the sub/function where you'll use them =) For the file related constants, I prefer to go with just "8" (or "1" or "2"). It's not like there is a bizilion different numbers to remember -there are only 3 of them- and they're easy to find in any doc, if really needed =)
Mine is shorter, I won !
I guess I win the price of the most buggy one then =p Already 2 patches out, before it even ran for the first time
-
[an]vicious
- Posts: 4
- Joined: 2003-03-04 07:27
-
ButterflySoul
- Posts: 210
- Joined: 2003-01-23 22:24
- Location: Nevada
The AttemptedConnection sub is triggered very early, so you can log connection attempts with it, but not the names, as it's the lock/key dialog trigering it, if I'm not wrong.
The UserConnected and OPConnected Subs are trigered later, when a user succesfully logs in (i.e. gives a correct key; and a correct pass in case the name is registered). In those 2 subs, you can track the username (and in the script I posted, that username is indeed mentioned in the log file, if you are loging successful connections).
The UserConnected and OPConnected Subs are trigered later, when a user succesfully logs in (i.e. gives a correct key; and a correct pass in case the name is registered). In those 2 subs, you can track the username (and in the script I posted, that username is indeed mentioned in the log file, if you are loging successful connections).
-
Marvin
- Posts: 147
- Joined: 2003-03-06 11:56
- Location: France
IP logging in Lua
My first Lua script : logging IPs on user connection.
Code: Select all
-- User Log script, by Marvin v0.2 04/16/2003
-- Saves the name, IP and time on user connection to an external file.
sLogfile = "userlog.txt" -- the file will be in the Scripts folder.
function NewUserConnected(curUser)
appendto(sLogfile)
write(curUser.sName,date(" connected %x at %X (IP: "),curUser.sIP,")\n")
writeto()
end
-
SB
- Posts: 1
- Joined: 2003-04-09 09:32
ok now to how to ..
save log using the date as the filename?
-
Sedulus
- Forum Moderator
- Posts: 687
- Joined: 2003-01-04 14:32
http://www.lua.org/manual/4.0/manual.html#6.5
http://www.scit.wlv.ac.uk/cgi-bin/mansec?3C+strftime
change
appendto(sLogfile)
to something like
appendto(date("logfile%m%d.txt"))
http://www.scit.wlv.ac.uk/cgi-bin/mansec?3C+strftime
change
appendto(sLogfile)
to something like
appendto(date("logfile%m%d.txt"))
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
Who is online
Users browsing this forum: Google [Bot] and 0 guests