mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
I have a folder that contains 100+ INI files. Each of these INI's contain the item "ipsused=" followed by a list of IP's seperated by commas. The system works when someone joins my gaming server. It's echoed through IRC and the bot records their IP that is displayed in a custom INI userfile which is stored in this directory with the 100+ other INI's.

I successfully got the bots to record all IP's each user has used in their userfile seperated by commas, but I want to make another script that will search in all the INI's for the given IP, and return the matching INI filename(s). So basically:

Joe_Dean: !searchip 1.2.3.4
Bot: The IP, 1.2.3.4, was used by <filename>.ini

I assume this would include aliases and $findfile, and please correct me if I'm wrong as I'm not very experienced with aliases, but using $2 to return the IP given inside the alias just returns blank. I can't seem to get this script working. smirk

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
1) Please supply an example as to the full format used in the ini files.. ie: Name, Section, Item, Value

You have supplied the Item and Value configurations, but to make this easier, I need to know if the Section is the same in each INI file. Also, it will help if you can tell me where these ini files are stored. (ie: the drive and full path, if fixed).

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
RusselB is right, more info might help.
Here's a quick shot, checking for the given IP everywhere in the "data" part of the inis (disregarding section/item names).
Note that you have to put your dir and channel to get it working.

Code:
; on text event. PUT THE CHANNEL to trigger at..
on *:text:!searchip &:#yourchannel: {

  ; check for $2 being a possible IP (checking for Number.Number.Number.Number)
  if ($regex($2,/^(\d+\.){3}\d+$/)) {

    ; store this IP to a variable
    set -e %ip.to.check $2

    ; PUT THE DIRECTORY that contains your ini files.
    var %dir = $mircdir

    ; perform a $findfile for all ini-files in this directory. trigger the alias "search.ips" with all inifiles found.
    noop $findfile(%dir,*.ini,0,1,search.ips $1-)

    ; after all ini files had been checked (alias search.ips):

    ; there are results written to a temp file "ipsfound.txt" 
    if ($isfile(ipsfound.txt)) {

      ; play this file to the channel (may avoid flood)
      .play -q5m3 $chan ipsfound.txt 500

      ; and remove the tempfile
      .remove ipsfound.txt 
    }

    ; there are no results written (no temp file found)
    else { msg $chan No matches for IP $2 found. }
  }

  ; $2 was no valid IP
  else { msg $chan Syntax is: !searchip <IP>, e.g. !searchip 1.2.3.4 }
}

; the search alias checking every ini-file in %dir
alias -l search.ips { 

  ; dummy filter command to get the number of matches in this file
  filter -gff $qt($1-) nul (?<==|,)\Q $+ %ip.to.check $+ \E(?=$|,)

  ; there are matches in this file: write the result to a temp file "ipsfound.txt".
  ; You might want to modify this output... atm: "File <inifile> contains <N> matches for IP <the IP given>"
  if ($filtered) { write ipsfound.txt File $nopath($1-) contains $v1 $iif(($v1 == 1),match,matches) for IP %ip.to.check }
}


Last edited by Horstl; 01/09/08 06:34 AM.
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
All INI's contain this:

[general]
ipsused=values

Values is obviously all the IP's separated by commas. The name of the INI's are obviously all different, so the point for this script is to return the name(s) of the files.

All INI's are located in a folder called 'userfiles' underneath mIRC's root directory (mIRC\userfiles). i.e. $mircdir $+ userfiles\*.ini

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
As long as you don't have other sections in the inis which use the same "ipsused=value" pattern, you can use the given script with some minor changes (dir-to-check, modified regex to match only items called "ipsused").

would work:
Code:
[general]
something=bla
ipsused=4.3.2.1,1.2.3.4,0.0.0.1
somethingelse=1.2.3.4
[misc]
name=hello

won't work, as theres a different section using the ipsused=value pattern:
Code:
[general]
something=bla
ipsused=4.3.2.1,1.2.3.4,0.0.0.1
somethingelse=1.2.3.4
[misc]
ipsused=0.0.0.1,1.2.3.4


Now, here's the slightly modified script, and without comments (it's structure did not change, thus you can refer to the comments above, if you want).
Code:
on *:text:!searchip &:#YOURCHANNEL: {
  if ($regex($2,/^(\d+\.){3}\d+$/)) {
    set -e %ip.to.check $2
    var %dir = $mircdir\userfiles
    noop $findfile(%dir,*.ini,0,1,search.ips $1-)
    if ($isfile(ipsfound.txt)) {
      .play -q5m3 $chan ipsfound.txt 500
      .remove ipsfound.txt 
    }
    else { msg $chan No matches for IP $2 found. }
  }
  else { msg $chan Syntax is: !searchip <IP>, e.g. !searchip 1.2.3.4 }
}

alias -l search.ips { 
  filter -gff $qt($1-) nul ^ipsused=(?:.+,)?\Q $+ %ip.to.check $+ \E(?=$|,)
  if ($filtered) {
    write ipsfound.txt IP %ip.to.check found in File $nopath($1-) $chr(40) $+ $v1 $iif(($v1 == 1),match,matches) $+ $chr(41) 
  }
}

...hope it works smile Note that there is no flood protection for the "no match" or "wrong syntax" messages. I suggest restricting the trigger to ops or the like (or add your own little flood protection).

Last edited by Horstl; 02/09/08 11:46 PM.
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Horstl,

It works great for the most part, except it's only showing matches if the IP specified is the entire value. For example, if Joe_Dean.ini has this inside the file:

[general]
ipsused=1.2.3.4, 5.6.7.8, 9.10.11.12

...and I typed !searchip 1.2.3.4, it would return a match of Joe_Dean.ini. HOWEVER, if I type: !searchip 9.10.11.12, it says no matches even though there is a match.

So the script is only looking to see if $2 equals the entire value. If $2 is in the value but not the first thing in the value, the script says there's no matches. Like I said, some files only have 1 IP, and some have multiple IP's seperated by commas. It all depends on how many users have Dynamic IP's. Understand what I'm trying to do here?

Other than that though - excellent script. Although I can't say I understand the point of the script showing how many matches. If it finds more than one match, it puts each match on its own line, showing "1 match" at the end of each line. So no matter what, it's always showing 1 match (obviously unless there is no matches).

Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Ah I see, I'm putting spaces between the IP's. My apologies, I didn't mention anything about that. I can make the other script that records the IP's to put each IP together separated by a comma instead of a comma then a space. Simple fix, no big deal.

So everything works great! I would still like to know though how the match count is useful. Thanks for this though, I really like it and it works perfectly.

Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Also, fyi, there is a very very small error in your code. I noticed it right as I added it so I didn't run into any problems, but...

$mircdir actually includes the end trailing slash (i.e. C:\Program Files\mIRC\), so the right way to use this identifier would be: $mircdir $+ userfiles :P

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Older versions of mIRC didn't include the final \ character as part of $mircdir, so some scripters have gotten into the habit of adding it. If you include the \ character appended to the $mircdir identifier and it's not required, mIRC will ignore it.

Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Ah, I see. Thanks.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hum, I added the matches to the first script because the first script scanned all items of each ini for the given IP in the value (data) part, and for testing purposes.
After changing the script to match only ipsused=data, and knowing now that you have max. one ipsused=data item per ini, it's useless indeed laugh

To get rid of this part, simply remove "$chr(40) $+ $v1 $iif(($v1 == 1),match,matches) $+ $chr(41)" in the write command (3d last line).
This line would become:
Code:
write ipsfound.txt IP %ip.to.check found in File $nopath($1-)


Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Yep, thanks again Horstl. laugh


Link Copied to Clipboard