This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

custom banmask

Help for those learning Tcl or writing their own scripts.
Post Reply
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

custom banmask

Post by simo »

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 :

*!*@host-233-net-99-160-119.mobilinkinfinity.net.pk

normally it would output with :
*!*@host-???-net-??-???-???.mobilinkinfinity.net.pk
we wanted to have it like this:
*!*@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 :

*!*@host-s2d3d3-net-sd99-160er-c119j.mobilinkinfinity.net.pk
this would output as :
*!*@host-s?d?d?-net-sd??-???er-c???j.mobilinkinfinity.net.pk
to have it like :
*!*@host-*-net-*-*-*.mobilinkinfinity.net.pk
thanks in advance
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You can easily get the first banmask you want:

Code: Select all

.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: Select all

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"
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

excellent that seems to work CC
anyway to have this a bit shorter like in regexp perhaps ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

String map it?

Code: Select all

% 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.
Last edited by caesar on Sun Jan 09, 2022 12:40 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

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 :)
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Ok I think I found it.

Works on the host part:

Code: Select all

.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: Select all

.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]
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

excellent that seems to do perfect thanks gents CC and caesar
Post Reply