mIRC Home    About    Download    Register    News    Help

Topic Options
#130386 - 17/09/05 08:29 AM hex2dec?
Abuser__ Offline
Babel fish

Registered: 21/04/05
Posts: 53
i need a script to resolve webchat IPs. Something like that:

I tipe !hex2dec c14d9486
and the bot answers: hex2dec: c14d9486 = 193.77.148.134

thanks smile

Top
#130387 - 17/09/05 08:52 AM Re: hex2dec?
dunkelzahn Offline
Babel fish

Registered: 10/12/02
Posts: 83
Loc: paris
You don't search a lot and we are not a scripter for you.

I find a text to explain how convert dec to hex. So, with reflexion, you can make in other sense.

Example 3: Primenet identifies its outgoing email server by the name: smtp.primenet.com, and by
the decimal IP address: 206.165.6.132. Convert the decimal address 206.165.6.132 to its
hexadecimal equivalent.
Treat each set of digits delimited by decimal points as a unique 3 digit decimal number. Convert each 3
digit decimal number into an equivalent 2 digit hexadecimal number.
Use the decimal to hexadecimal algorithm above to convert 206 decimal to its hexadecimal equivalent.
Step 1: 206/16=12.875. Keep the whole number, 12, and ignore the remainder.
Step 2: Convert decimal 12 to hexadecimal using Table 1.
DEC: 12
HEX: C
Step 3: 12x16=192.
Step 4: 206-192=14.
Step 5: Convert decimal 14 to hexadecimal using Table 1.
DEC: 14
HEX: E
The equivalent hexadecimal is CE.
Using the same procedure defined above, the remaining segments of the email address are converted as
follows:
DEC: 165
HEX: A5
DEC: 6
HEX: 06
DEC: 132
HEX: 84
The equivalent hexadecimal address is CE.A5.06.84.

Top
#130388 - 17/09/05 10:17 AM Re: hex2dec?
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
Assuming you want it to work in queries (private messages) only the code would be:

Code:
on *:text:!hex2dec &:?:msg $nick hex2dec: $2 = $longip($base($2,16,10))
_________________________
Spelling mistakes, grammatical errors, and stupid comments are intentional.

Top
#130389 - 17/09/05 11:23 AM Re: hex2dec?
Om3n Offline
Fjord artisan

Registered: 06/07/03
Posts: 655
Syntax: $dec2hex(ip) or $hex2dec(ip)
dec2hex will return period denominated hex, $remove($dec2hex(ip)) can be used to return hex without periods. hex2dec will detect if periods are in the hex and return correctly for both

Code:
alias dec2hex {
  if (!$1) return
  else return $+($base($gettok($1,1,46),10,16,2),.,$base($gettok($1,2,46),10,16,2),.,$base($gettok($1,3,46),10,16,2),.,$base($gettok($1,4,46),10,16,2))
}
alias hex2dec {
  if (!$1) return
  return $iif($len($2) == 8, $longip($base($1,16,10)), $longip($base($remove($1,.),16,10)))
}


Sample triggers

Code:
on *:TEXT:!d2h *:# {
  if (!$2) msg # Syntax: !d2h <decip>
  else msg # Dec2Hex: $2 <> $dec2hex($2)
}
on *:TEXT:!h2d *:# {
  if (!$2) msg # Syntax: !h2d <hexip>
  else msg # Hex2Dex: $2 <> $hex2dec($2)
}
_________________________
"Allen is having a small problem and needs help adjusting his attitude" - Flutterby

Top
#130390 - 19/09/05 11:43 AM Re: hex2dec?
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
Here's an alternative to your dec2hex code:

Code:
alias dec2hex { 
  tokenize 46 $$1
  scon -r var $(%a = %a,) $!base( $* ,10,16,2)
  return $replace(%a,$chr(32),.)
}
_________________________
Gone.

Top
#130391 - 22/09/05 02:34 PM Re: hex2dec?
Om3n Offline
Fjord artisan

Registered: 06/07/03
Posts: 655
Could you explain how that works, i understand the tokenize, replace and scon commands. but the '$(%a = %a,) $!base( $* ,10,16,2)' part is an unfamiliar way of processing to me.

Why is the scon neccersary for the variable to be set correctly, what purpose does the explanation mark have between the $ and the command name like that, and what is $* (possibly same as $1- but tells it to process the identifier its in for each? shrug). tia
_________________________
"Allen is having a small problem and needs help adjusting his attitude" - Flutterby

Top