Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
/ dns4s Public archive
forked from mkroli/dns4s

Scala DNS implementation with Akka and Netty extension

License

Notifications You must be signed in to change notification settings

d2iq-archive/dns4s

 
 

Repository files navigation

dns4s

dns4s is an implementation of the DNS protocol in Scala. It consists of the following parts:

  • Core
  • Akka IO Extension

Core

The core part contains the classes and objects used for en-/decoding of DNS messages as well as an inner-DSL to con-/destruct DNS messages.

Akka IO Extension

The akka part contains an akka-io extension.

Usage

If you're using sbt just add the following to your build definition:

resolvers += "bintray" at "http://jcenter.bintray.com"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.3.2",
  "com.github.mkroli" %% "dns4s-akka" % "0.3")

Imports

Use the following imports to get started:

import akka.actor._
import akka.io.IO
import com.github.mkroli.dns4s.dsl._
import com.github.mkroli.dns4s.akka._
import scala.concurrent.duration._

Server

The following is an excerpt from examples/simple/../DnsServer.scala:

class DnsHandlerActor extends Actor {
  override def receive = {
    case Query(_) ~ Questions(QName(host) ~ TypeA() :: Nil) =>
      sender ! Response ~ Questions(host) ~ Answers(ARecord("1.2.3.4"))
  }
}

object DnsServer extends App {
  implicit val system = ActorSystem("DnsServer")
  implicit val timeout = Timeout(5 seconds)
  IO(Dns) ? Dns.Bind(system.actorOf(Props[DnsHandlerActor]), 5354)
}

Client

The following is an excerpt from examples/simple-client/../DnsClient.scala:

implicit val system = ActorSystem("DnsServer")
implicit val timeout = Timeout(5 seconds)
import system.dispatcher

IO(Dns) ? Dns.DnsPacket(Query ~ Questions("google.de"), new InetSocketAddress("8.8.8.8", 53)) onSuccess {
  case Response(Answers(answers)) =>
    answers.collect {
      case ARecord(arecord) => println(arecord.address.getHostAddress)
    }
}

About

Scala DNS implementation with Akka and Netty extension

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%