Created
February 1, 2012 19:36
-
-
Save raws/1718820 to your computer and use it in GitHub Desktop.
Example SRV record lookup for Minecraft servers
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
$ host -t SRV _minecraft._tcp.survival.blolol.com | |
_minecraft._tcp.survival.blolol.com has SRV record 0 1 25565 minecraft.blolol.com. | |
$ host -t SRV _minecraft._tcp.creative.blolol.com | |
_minecraft._tcp.creative.blolol.com has SRV record 0 1 25566 minecraft.blolol.com. | |
$ java -jar SRVLookupTest.jar survival.blolol.com | |
minecraft.blolol.com:25565 | |
$ java -jar SRVLookupTest.jar creative.blolol.com | |
minecraft.blolol.com:25566 |
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
package com.rosspaffett.srv; | |
import org.xbill.DNS.Lookup; | |
import org.xbill.DNS.Record; | |
import org.xbill.DNS.SRVRecord; | |
import org.xbill.DNS.TextParseException; | |
import org.xbill.DNS.Type; | |
public class SRVLookupTest { | |
public static void main(String[] args) { | |
if (args.length < 1) { | |
System.err.println("Usage: java -jar SRVLookupTest <hostname>"); | |
System.exit(1); | |
} | |
String query = "_minecraft._tcp." + args[0]; | |
try { | |
Record[] records = new Lookup(query, Type.SRV).run(); | |
for (Record record : records) { | |
SRVRecord srv = (SRVRecord)record; | |
String hostname = srv.getTarget().toString().replaceFirst("\\.$", ""); | |
int port = srv.getPort(); | |
System.out.println(hostname + ":" + port); | |
} | |
} catch (TextParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment