Logging IP Addresses

Which hub software is the best? Where can I find script XXX? Discuss it here...(no, this is not for advertising your hub...)

Moderator: Moderators

Alpinex
Posts: 1
Joined: 2003-02-04 20:28

Logging IP Addresses

Post by Alpinex » 2003-03-10 20:56

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

ButterflySoul
Posts: 210
Joined: 2003-01-23 22:24
Location: Nevada

Post by ButterflySoul » 2003-03-10 21:27

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 ! =)

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
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

ButterflySoul
Posts: 210
Joined: 2003-01-23 22:24
Location: Nevada

Post by ButterflySoul » 2003-03-10 21:31

Ooops =) Small typo on top. The line :

If Not fso.FolderExists(".\ConnectLog") Then .CreateFolder(".\ConnectLog")


Should be :

Code: Select all

If Not fso.FolderExists(".\ConnectLog") Then fso.CreateFolder(".\ConnectLog") 
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

Marvin
Posts: 147
Joined: 2003-03-06 11:56
Location: France

Post by Marvin » 2003-03-10 21:41

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

Post by ender » 2003-03-10 22:01

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

Post by ButterflySoul » 2003-03-10 22:15

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...

.WriteLine Time & " : " sEntry


Should be

Code: Select all

.WriteLine Time &" : " &sEntry


This time it should work.. Sowwy :oops:
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

Marvin
Posts: 147
Joined: 2003-03-06 11:56
Location: France

Post by Marvin » 2003-03-10 22:18

Mine is shorter, I won ! 8)

(To be honest, it doesn't achieve much things) :wink:

smitty
Posts: 53
Joined: 2003-03-01 19:45

Post by smitty » 2003-03-11 01:02

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

Post by ButterflySoul » 2003-03-11 04:30

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 :wink:
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

Marvin
Posts: 147
Joined: 2003-03-06 11:56
Location: France

Post by Marvin » 2003-03-11 13:22

smitty wrote:guys lets not forget one thing...to read, write, and append you gotta define the constant above the Sub Main()

I'm to lazy to produce clean code, so I wrote 8..... :oops:

[an]vicious
Posts: 4
Joined: 2003-03-04 07:27

Post by [an]vicious » 2003-04-02 14:21

can u make it so the script also writes the name that the user connect with so in the log file it shows:

255.255.255.255 [an]vicious

Marvin
Posts: 147
Joined: 2003-03-06 11:56
Location: France

Post by Marvin » 2003-04-02 19:39

In my code, it's impossible as the user has not send his name to the hub when the line is writen.

In other codes, just add &curuser.sname to the string

ButterflySoul
Posts: 210
Joined: 2003-01-23 22:24
Location: Nevada

Post by ButterflySoul » 2003-04-02 22:24

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).
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

Marvin
Posts: 147
Joined: 2003-03-06 11:56
Location: France

IP logging in Lua

Post by Marvin » 2003-04-16 10:54

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 ..

Post by SB » 2003-04-24 05:19

save log using the date as the filename?

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 14:32

Post by Sedulus » 2003-04-24 11:48

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://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)

Who is online

Users browsing this forum: Google [Bot] and 0 guests