| View previous topic :: View next topic |
| Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun Jan 09, 2022 10:28 am Post subject: custom banmask |
|
|
i was wondering if this banmask: [maskhost $uhost 14]
wich replaces all digits in the hosts with a ?
could be converted to replace all ? chars with a single *
for example :
| Quote: | | *!*@host-233-net-99-160-119.mobilinkinfinity.net.pk |
normally it would output with :
| Quote: | | *!*@host-???-net-??-???-???.mobilinkinfinity.net.pk |
we wanted to have it like this:
| Quote: | | *!*@host-*-net-*-*-*.mobilinkinfinity.net.pk |
so the sections with digit in it should be replaced with a single asterix even if the section has alphabetical chars in it as well
sor for example :
| Quote: | | *!*@host-s2d3d3-net-sd99-160er-c119j.mobilinkinfinity.net.pk |
this would output as :
| Quote: | | *!*@host-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk |
to have it like :
| Quote: | | *!*@host-*-net-*-*-*.mobilinkinfinity.net.pk |
thanks in advance |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sun Jan 09, 2022 11:36 am Post subject: |
|
|
You can easily get the first banmask you want:
| Code: | .tcl set target "*!*@host-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk"
.tcl regsub -all -- {\?+} $target {*} target
.tcl putlog $target
[16:06] *!*@host-s*d*d*-net-sd*-*er-c*j.mobilinkinfinity.net.pk |
To replace any part containing ? (or *) with *, it's more difficult as you have 2 separators (- and .), so you'll have to split host on "." and loop on that, then split on - and replace if needed:
| Code: | set target "*!*@host-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk"
lassign [split $target @] u h
append u @
set th {}
foreach m1 [split $h .] {
set thd {}
foreach m2 [split $m1 -] {
if {[string first ? $m2]!=-1} {
lappend thd *
} else {
lappend thd $m2
}
}
lappend th [join $thd -]
}
append u [join $th .]
putlog "U is $u" |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun Jan 09, 2022 11:54 am Post subject: |
|
|
excellent that seems to work CC
anyway to have this a bit shorter like in regexp perhaps ? |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sun Jan 09, 2022 12:38 pm Post subject: |
|
|
String map it?
| Code: |
% set text "*!*@host-???-net-??-???-???.mobilinkinfinity.net.pk"
% string map {? *} $text
*!*@host-***-net-**-***-***.mobilinkinfinity.net.pk
|
Edit: Nvm, doesn't seem to get as you wanted. _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Sun Jan 09, 2022 12:40 pm; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sun Jan 09, 2022 12:39 pm Post subject: |
|
|
As I said: complicated as you have 2 possible separators.
I'm doing some tries with regexp but I won't bet a lot on it  _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sun Jan 09, 2022 1:04 pm Post subject: |
|
|
Ok I think I found it.
Works on the host part:
| Code: | .tcl set target "host-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk"
.tcl regsub -all -- {([a-z\?]*\?{1,}[a-z\?]*)(-|\.|$)} $target {*\2} target
.tcl putlog $target
[18:04] host-*-net-*-*-*.mobilinkinfinity.net.pk |
Seems to work on full mask too:
| Code: | .tcl set target "nick!username@ho?st-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk"
.tcl regsub -all -- {([a-z\?]*\?{1,}[a-z\?]*)(-|\.|$)} $target {*\2} target
.tcl putlog $target
[18:05] nick!username@*-*-net-*-*-*.mobilinkinfinity.net.pk |
I added a ? in the beginning of the host to check if we won't have nick!username@ho?st replaced with *, but it's ok as @ is not in [a-z] _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Sun Jan 09, 2022 1:27 pm Post subject: |
|
|
| excellent that seems to do perfect thanks gents CC and caesar |
|
| Back to top |
|
 |
|