# Converting network and gateway from routing table to hexadecimal string

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
```#
# Script converting network and gateway from routing table to hexadecimal string
#
# (c) Daniel Starnowski 2011
#
:foreach route in=[/ip route find] do={
:local dst [/ip route get \$route dst-address];
:local gateway [/ip route get \$route gateway];
:if (\$gateway=[:toip \$gateway]) do={
:local total (\$dst . "." . \$gateway);
:local result "0x";
:local hextable [:toarray "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f"];
:local total2 "";
:local decimal;
:local division;
:local i;
:local j;
:for i from=1 to=[:len \$total] step=1 do={
:set j [:pick \$total (\$i-1) \$i];
:if ((\$j=".") or (\$j="/")) do={:set j ","};
:set total2 (\$total2 . \$j);
};
:set total2 [:toarray \$total2];

:for i from=0 to=8 step=1 do={
:set j \$i;
:if (\$j<5) do={if (\$j=0) do={:set j 4;} else={:set j (\$j-1);};};
:set decimal [:pick \$total2 \$j (\$j+1)]
:set division (\$decimal / 16);
:set result (\$result . [:pick \$hextable \$division]);
:set result (\$result . [:pick \$hextable (\$decimal - (16 * \$division))]);
};
:put \$result;
} else={:put ("Gateway is not a single IP address for ".\$dst);}
}```