Created
November 14, 2016 14:47
-
-
Save walkure/55a9ad539658f4b05e80198283480c4d to your computer and use it in GitHub Desktop.
Multicast DNS test code
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use IO::Socket::Multicast; | |
use Net::DNS::Packet; | |
my $target = '224.0.0.251'; | |
my $port = 5353; | |
my $host = 'altair'; | |
my $tld = 'local'; | |
$|=1; | |
my $rsock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>$port,ReuseAddr=>1) or die "cannot make recv sock:$!\n"; | |
$rsock->mcast_add($target); | |
my $header = pack('nnnnnn',0,0,1,0,0,0); | |
my $query = pack('cA*cA*cnn',length($host),$host,length($tld),$tld,0,1,1); | |
$rsock->mcast_send($header.$query,"$target:$port"); | |
#my $query = new Net::DNS::Packet( 'altair.local', 'A', 'IN' ); | |
#$rsock->mcast_send($query->data,"$target:$port"); | |
while(1) | |
{ | |
my $data; | |
$rsock->recv($data,128); | |
print "$data\n"; | |
my $dep = new Net::DNS::Packet(\$data); | |
$dep->print; | |
print "[".(scalar localtime)."]:======================\n"; | |
# sleep 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment