gpt4 book ai didi

java - 从跟踪器中的 udp url/地址获取 ip

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:01 27 4
gpt4 key购买 nike

在 Java 中,或者更一般地说,如果我有一个跟踪器公告 URL,如:udp://tracker.coppersurfer.tk:6969,我如何获取 IP 地址以添加到需要 InetAddressDataGramPacket 构造函数中?

或者我是否遗漏了某些内容,而这些信息可以在 .torrent 文件中的其他位置找到?

在 BitTorrent 规范中,我只能找到如何使用 http 地址完成它,但我发现的所有 torrent 都使用 udp 作为其跟踪器。

最佳答案

如今运行流行的公共(public) http 跟踪器几乎是不可能的。因为它们需要太多的资源来运行。当跟踪器变得流行时,它必须仅使用UDP

BitTorrent UDP 跟踪器在 BEP15 - UDP Tracker Protocol 中指定.

要获取 URL 的 IP 地址,请使用 DNS。

来自Get IP address with URL string? (Java)的回答通过 Victor Stafusa :

Try this:

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

To get the raw IP:

String ip = address.getHostAddress();

关于java - 从跟踪器中的 udp url/地址获取 ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44475339/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com