[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] hexadecimal / traffic control
From: |
Reinaldo Carvalho |
Subject: |
Re: [shell-script] hexadecimal / traffic control |
Date: |
Fri, 28 Jul 2006 23:39:31 -0300 |
Tiago,
echo '0a0a2200/ffffff00' | awk --non-decimal-data -F '/' 'function
x(s,p){ return sprintf("%d","0x"z(s,p)) } function z(s,p){ return
substr(s,p,2) } function y(s){ return
x(s,1)"."x(s,3)"."x(s,5)"."x(s,7) } { print y($1),"/",y($2) }'
Funcionou perfeitamente, só que depois de analisar melhor, a segunda
parte (ffffff00), tenho que converter de hexadecimal para bits, na
verdade preciso saber quantos bits tem nesse hexadecimal.
80000000 = 1000 0000 0000 0000 0000 0000 0000 0000 = 1
c0000000 = 1100 0000 0000 0000 0000 0000 0000 0000 = 2
e0000000 = 1110 0000 0000 0000 0000 0000 0000 0000 = 3
f0000000 = 1111 0000 0000 0000 0000 0000 0000 0000 = 4
f8000000 = 1111 1000 0000 0000 0000 0000 0000 0000 = 5
fc000000 = 1111 1100 0000 0000 0000 0000 0000 0000 = 6
fe000000 = 1111 1110 0000 0000 0000 0000 0000 0000 = 7
ff000000 = 1111 1111 0000 0000 0000 0000 0000 0000 = 8
ff800000 = 1111 1111 1000 0000 0000 0000 0000 0000 = 9
ffc00000 = 1111 1111 1100 0000 0000 0000 0000 0000 = 10
ffe00000 = 1111 1111 1110 0000 0000 0000 0000 0000 = 11
fff00000 = 1111 1111 1111 0000 0000 0000 0000 0000 = 12
fff80000 = 1111 1111 1111 1000 0000 0000 0000 0000 = 13
fffc0000 = 1111 1111 1111 1100 0000 0000 0000 0000 = 14
fffe0000 = 1111 1111 1111 1110 0000 0000 0000 0000 = 15
ffff0000 = 1111 1111 1111 1111 0000 0000 0000 0000 = 16
ffff8000 = 1111 1111 1111 1111 1000 0000 0000 0000 = 17
ffffc000 = 1111 1111 1111 1111 1100 0000 0000 0000 = 18
ffffe000 = 1111 1111 1111 1111 1110 0000 0000 0000 = 19
fffff000 = 1111 1111 1111 1111 1111 0000 0000 0000 = 20
fffff800 = 1111 1111 1111 1111 1111 1000 0000 0000 = 21
fffffc00 = 1111 1111 1111 1111 1111 1100 0000 0000 = 22
fffffe00 = 1111 1111 1111 1111 1111 1110 0000 0000 = 23
ffffff00 = 1111 1111 1111 1111 1111 1111 0000 0000 = 24
ffffff80 = 1111 1111 1111 1111 1111 1111 1000 0000 = 25
ffffffc0 = 1111 1111 1111 1111 1111 1111 1100 0000 = 26
ffffffe0 = 1111 1111 1111 1111 1111 1111 1110 0000 = 27
fffffff0 = 1111 1111 1111 1111 1111 1111 1111 0000 = 28
fffffff8 = 1111 1111 1111 1111 1111 1111 1111 1000 = 29
fffffffc = 1111 1111 1111 1111 1111 1111 1111 1100 = 30
fffffffe = 1111 1111 1111 1111 1111 1111 1111 1110 = 31
ffffffff = 1111 1111 1111 1111 1111 1111 1111 1111 = 32
Exemplo de entrada e saida.. (sem espaços em branco na reposta)
$ echo 0a0a2200/ffffff00 | awk ...
10.10.34.0/24
$ echo 0a0a2200/ffff0000 | awk ...
10.10.34.0/16
Uma lógica é somar... f=4, e=3, c=2, 8=1
On 7/27/06, Tiago Barcellos Peczenyj <address@hidden> wrote:
pipe? sim
echo '0a0a2200/ffffff00' | awk --non-decimal-data -F '/' 'function
x(s,p){ return sprintf("%d","0x"z(s,p)) } function z(s,p){ return
substr(s,p,2) } function y(s){ return
x(s,1)"."x(s,3)"."x(s,5)"."x(s,7) } { print y($1),"/",y($2) }'
--
Reinaldo Carvalho
Debian Sarge 3.1 - Linux User: #238310
Prodepa - address@hidden
Re: [shell-script] hexadecimal / traffic control, Tiago Barcellos Peczenyj, 2006/07/27
- Re: [shell-script] hexadecimal / traffic control, Reinaldo Carvalho, 2006/07/27
- Re: [shell-script] hexadecimal / traffic control, Tiago Barcellos Peczenyj, 2006/07/27
- Re: [shell-script] hexadecimal / traffic control,
Reinaldo Carvalho <=
- Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/28
- Re: [shell-script] hexadecimal / traffic control, Julio C. Neves, 2006/07/29
- Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/29
- Re: [shell-script] hexadecimal / traffic control, Julio C. Neves, 2006/07/29
- Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/29
- Re: [shell-script] hexadecimal / traffic control, Julio C. Neves, 2006/07/30
- Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/30
- Re: [shell-script] hexadecimal / traffic control, Julio C. Neves, 2006/07/30
- Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/31
Re: [shell-script] hexadecimal / traffic control, Felipe Kellermann, 2006/07/28