Created
March 8, 2016 21:42
-
-
Save kgersen/689ad74c116d0ad1af6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="ipaddr.min.js"> | |
/* https://github.com/whitequark/ipaddr.js/ */ | |
</script> | |
<script> | |
/* | |
from: https://lafibre.info/free-10g-epon/zones-de-test-zmd/msg312896/#msg312896 | |
*/ | |
var pfx4 = ipaddr.parse("91.0.0.0"); | |
var pfx6 = ipaddr.parse("2a01:e00::"); | |
function is_in_Free_4rd_dom(ip6) | |
{ | |
return ip6.match(pfx6,24); // TODO: /24 is a guess, get the real Free/Iliad 4rd prefix | |
} | |
function ip6_to_ip4(ip6) { | |
var ip4 = ipaddr.fromByteArray([ | |
pfx4.octets[0], | |
((ip6.parts[1] & 0xF) << 4) | ((ip6.parts[2] >> 8) & 0x3), | |
((ip6.parts[2] & 0x3F) <<2) | (ip6.parts[3] >> 14), | |
(ip6.parts[3] >> 6) & 0xFF | |
] | |
); | |
return ip4; | |
} | |
function ip6_to_ip4_port_range(ip6) { | |
//(ip6 << 10) & 0xc000 | |
return ((ip6.parts[3]>>8) & 0x3); | |
} | |
function port_range_to_range(pr) { | |
switch(pr) | |
{ | |
case 0: return {from:0 , to:16383}; | |
case 1: return {from:16384, to:32767}; | |
case 2: return {from:32768, to:49151}; | |
case 3: return {from:49152, to:65535}; | |
} | |
} | |
/* | |
function ip4_to_ip6(ip4,port_range) | |
{ | |
//TODO | |
} | |
*/ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment