egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

custom banmask

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Sun Jan 09, 2022 10:28 am    Post subject: custom banmask Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Sun Jan 09, 2022 11:36 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Sun Jan 09, 2022 11:54 am    Post subject: Reply with quote

excellent that seems to work CC
anyway to have this a bit shorter like in regexp perhaps ?
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sun Jan 09, 2022 12:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Sun Jan 09, 2022 12:39 pm    Post subject: Reply with quote

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 Smile
_________________
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
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Sun Jan 09, 2022 1:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Sun Jan 09, 2022 1:27 pm    Post subject: Reply with quote

excellent that seems to do perfect thanks gents CC and caesar
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber