1

In Java, or more generally, if I have a tracker announce url like: udp://tracker.coppersurfer.tk:6969, how can I acquire the ip address to add to the constructor of a DataGramPacket that requires an InetAddress?

Or am I missing something and this information is available somewhere else in a .torrent file?

In the BitTorrent specification I can only find how it is done with http addresses but all torrents I find use udp for their trackers.

Jesper
  • 472
  • 1
  • 4
  • 14

1 Answers1

0

It's close to impossible to run a popular public http tracker today. as they take too much resources to run. When a tracker gets to popular, it has to use only UDP.

BitTorrent UDP trackers are specified in BEP15 - UDP Tracker Protocol.

To get the IP-address for the URL, use DNS.

Answer from Get IP address with URL string? (Java) by Victor Stafusa:

Try this:

InetAddress address = InetAddress.getByName(new URL(urlString).getHost());

To get the raw IP:

String ip = address.getHostAddress();

Community
  • 1
  • 1
Encombe
  • 2,003
  • 1
  • 17
  • 26
  • I understand the reasoning behind it but I don't know where to send the packet to. – Jesper Jun 10 '17 at 17:51
  • Ok, I thought DNS was only used for http. Do you know of any Java library for this or another resouce to check out? Have tried googling it quite a bit but found nothing useful. – Jesper Jun 10 '17 at 18:03
  • I think I misunderstood how DNS works. Thought it needed the protocol to look things up but it only uses the domain name. That makes a lot of sense. It is possible to simply use the getByName method on the domain name. – Jesper Jun 10 '17 at 18:32
  • Thanks for the replies! – Jesper Jun 10 '17 at 18:32
  • Note that you should use `getAllByName` instead, since a tracker may have ipv4 and ipv6 addresses and you need to announce to one per address family – the8472 Jun 10 '17 at 19:23