Last active
December 18, 2021 14:35
-
-
Save Chaz6/0af1271092b52c74f2c67c7a9cb0745a to your computer and use it in GitHub Desktop.
Generate a hosts file using DNS64
This file contains hidden or 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
www.example.com 93.184.216.34 |
This file contains hidden or 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
#!/usr/bin/env perl | |
use strict; | |
use Net::IP qw(ip_is_ipv4 ip_is_ipv6 ip_compress_address); | |
my $domains_file = 'domains.txt'; | |
my $prefixes_file = 'prefixes.txt'; | |
sub convert_ip_to_hex { | |
my $prefix = shift; | |
my $addr = shift; | |
my ($a,$b,$c,$d) = split(/\./, $addr); | |
$a = sprintf("%02x", $a); | |
$b = sprintf("%02x", $b); | |
$c = sprintf("%02x", $c); | |
$d = sprintf("%02x", $d); | |
my $ip = $a.$b.":".$c.$d; | |
my $ip1 = new Net::IP('::'.$ip); | |
my $ip2 = new Net::IP($prefix); | |
my $ip3 = $ip1->binadd($ip2); | |
return ip_compress_address($ip3->ip(),6); | |
} | |
my %domains; | |
open my $fh, '<', $domains_file or die; | |
while (my $row = <$fh>) { | |
chomp $row; | |
my ($domain, $ip) = split(/ /,$row); | |
push(@{$domains{$domain}},$ip); | |
} | |
close $fh; | |
my @prefixes; | |
open $fh, '<', $prefixes_file or die; | |
while (my $row = <$fh>) { | |
chomp $row; | |
push(@prefixes,$row); | |
} | |
close $fh; | |
foreach my $domain (keys %domains) { | |
foreach my $ip (@{$domains{$domain}}){ | |
foreach my $prefix (@prefixes) { | |
if(ip_is_ipv6($prefix) && ip_is_ipv4($ip)) { | |
print convert_ip_to_hex($prefix,$ip)." ".$domain."\n"; | |
} | |
} | |
} | |
} |
This file contains hidden or 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
2a0b:f4c0:4d:1:: | |
2a0b:f4c0:4d:2:: | |
2a0b:f4c0:4d:3:: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment