captiveportal_fakedns 729 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Net::DNS::Nameserver;
  5. my $ip4_addr = shift @ARGV;
  6. sub reply_handler {
  7. my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
  8. my ($rcode, @ans, @auth, @add);
  9. if($qtype eq "A") {
  10. my ($ttl, $rdata) = (1, $ip4_addr);
  11. my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
  12. push @ans, $rr;
  13. $rcode = "NOERROR";
  14. } else {
  15. $rcode = "NXDOMAIN";
  16. }
  17. return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
  18. }
  19. my $ns = new Net::DNS::Nameserver(
  20. LocalPort => 4253,
  21. LocalAddr => $ip4_addr,
  22. ReplyHandler => \&reply_handler,
  23. Verbose => 0
  24. ) || die "Couldn't create fake nameserver object.\n";
  25. $ns->main_loop;
  26. exit 0;