0.0.0.0 是有效的 IP 地址吗?

发布于 2024-09-18 04:18:08 字数 71 浏览 4 评论 0原文

0.0.0.0 是有效的 IP 地址吗?我希望我的程序能够将其存储为没有地址正在使用的指示,但如果它实际上有效,则这将不起作用。

Is 0.0.0.0 a valid IP address? I want my program to be able to store it as an indication that no address is in use, but this won't work if it's actually valid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

恬淡成诗 2024-09-25 04:18:09

0.0.0.0 用于绑定所有 IPv4 接口。所以它是一个特殊的值,就像 127.0.0.1 一样。

The 0.0.0.0 is used to bind all IPv4 interfaces. So it's a special value just like 127.0.0.1.

小嗲 2024-09-25 04:18:09

是的,它是一个 IP 地址它是保留的。

0.0.0.0/8 - 此块中的地址引用“此”上的源主机
网络。地址 0.0.0.0/32 可以用作此的源地址
该网络上的主机; 0.0.0.0/8 内的其他地址可用于
引用该网络上的指定主机

Yes, it is an IP address but it is reserved.

0.0.0.0/8 - Addresses in this block refer to source hosts on "this"
network. Address 0.0.0.0/32 may be used as a source address for this
host on this network; other addresses within 0.0.0.0/8 may be used to
refer to specified hosts on this network

[浮城] 2024-09-25 04:18:09

它被保留为默认路由地址。

当没有为您分配地址时,通过 ipconfig 经常会看到这种情况。

It's reserved as the default route address.

It's common to see this via ipconfig when no address has been assigned to you.

不如归去 2024-09-25 04:18:09

出于所有意图和目的,是的。由句点分隔的四个数字中的每一个的值范围为 0-255,因此 0.0.0.0 在技术上是有效的。

但我认为世界上没有人真正拥有该知识产权。

编辑:好的,它是为默认路由保留的,但它仍然有效。

for all intents and purposes, yes. Each of the four numbers separated by the period have a value ranging from 0-255, so 0.0.0.0 is technically valid.

I don't think that there would be anyone in the world who actually has that IP though.

EDIT: okay, it is reserved for the default route, but it is still valid.

淡墨 2024-09-25 04:18:09

你可以在你的应用程序中使用它来表示它没有IP地址,当机器没有IP地址时微软也会使用0.0.0.0。

上面讨论的“有效”场景取决于具体场景,与您的应用程序无关。

You can use it in your application to represent that it does not have an IP address, Microsoft also uses 0.0.0.0 when the machine has no IP address.

the "Valid" scenarios talked about above are dependent on the specific scenarios where they have nothing to do with your application.

风向决定发型 2024-09-25 04:18:09

执行网络 Whois 查询也可以产生非常有用的输出。
示例:
http://whois.arin.net/rest/网;q=0.0.0.0?showDetails=true

注释:当计算机正在学习它应该使用哪个 IP 地址时,地址 0.0.0.0 只能用作传出数据包的地址。它永远不会用作目标地址。以“0”开头的地址。有时用于向直接连接的设备进行广播。

Doing a Network Whois query can also produce output that is quite helpful.
Example:
http://whois.arin.net/rest/nets;q=0.0.0.0?showDetails=true

Comment: The address 0.0.0.0 may only be used as the address of an outgoing packet when a computer is learning which IP address it should use. It is never used as a destination address. Addresses starting with "0." are sometimes used for broadcasts to directly connected devices.

此刻的回忆 2024-09-25 04:18:09

正如其他答案所涵盖的那样,0.0.0.0 对于某些目的来说是合法且有效的 IP 地址。

如果范围内的所有值都是合法值,那么您要定义的任何标志项都必须来自其他地方。否则,您将使用标志含义重载合法值,并且在使用重载值时,将无法 100% 确定合法值或标志含义是否是预期的。这将导致错误,必须通过重构来解决,这可能是一项昂贵的工作。

超载合法值时常发生,IP 地址和 MAC 地址(是的,00:00:00:00:00:00 是合法且已分配的)是最常见的受害者。

巧合的是,我现在正在开发一个系统(不是基于以太网/IP),其中帧的长度上限约为 40 字节。由于一个字节可以表示 0 - 255 字节的长度,并且最大长度为 40 字节,因此我可以使用一些未使用的又名非法值(252 到 255)来表示标志项。这些带内标志没问题,因为没有过载。

As other answers have covered, 0.0.0.0 is a legal and valid for some purposes IP address.

If all values in a range are legal values, then any flag items you want to define must come from somewhere else. Otherwise you will overload a legal value with the meaning of a flag, and when using the overloaded value it won't be 100% possible to determine whether the legal value or the flag meaning was intended. This will lead to bugs which must be solved with a re-factor which can be an expensive endeavour.

Overloading legal values happens all the time, IP address and MAC addresses (yes, 00:00:00:00:00:00 is legal and allocated) are some of the most common victims.

Coincidentally, I am working on a system (not ethernet/IP based) now where the length of a frame is capped at about 40 bytes. Since a byte can represent lengths of 0 - 255 bytes, and the max length is 40 bytes, I can use some of the unused aka non-legal values (252 to 255) to represent flag items. These in-band flags are okay because there is no overloading.

半寸时光 2024-09-25 04:18:09

当然是。
但是,它对于网络上的单个主机无效。它在本地网络的广播范围内。阅读此处:https://www.rfc-editor.org/rfc/rfc1700

of course it is.
it will not be valid for a single host on a network however. it is in the broadcast range for the local network. read here: https://www.rfc-editor.org/rfc/rfc1700

梦里寻她 2024-09-25 04:18:08

有效,因为它包含四个八位位组,每个八位位组都在 0 到 255(含)范围内。但是,它不能用作真实的 IP 地址。

RFC1700 (a) 声明 0.0.0.0 /8 (0...) 仅保留作为源地址。您可能会遇到这样的情况:您似乎拥有该地址,但这通常是因为没有为您分配地址(例如,通过 DHCP)。

另请参阅有关 IPv4 的维基百科条目


(a) 虽然此 RFC 现在被认为已过时,但就给定行为而言它仍然是正确的。它的替代品 https://www.iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml,仍然有相同的文本详细说明 0.0.0.0 地址的使用。

It is valid inasmuch as it contains four octets, each within the range 0 through 255 inclusive. However, it is not usable as a real IP address.

RFC1700 (a) states that 0.0.0.0/8 (0.<anything>.<anything>.<anything>) is reserved as a source address only. You can get into situation where it appears you have this address but that's normally because no address has been assigned to you (by DHCP, for example).

See also Wikipedia entry on IPv4.


(a) Although this RFC is now considered obsolete, it is still correct in terms of the given behaviour. Its replacement, https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml, still has the same text detailing use of the 0.0.0.0 address.

暖伴 2024-09-25 04:18:08

让我们看看OP在这里提出的问题。

0.0.0.0 是有效的 IP 地址吗?

是的。从技术上讲,这是一个有效的 IP 地址,其他答案描述了它的许多不同用途(我不会重新发布

因此,我相信上面的 paxdiablo 的答案是最正确的,但让我们看看你的问题的上下文。

我希望我的程序能够将其存储为没有地址正在使用的指示,但如果它实际上有效,则这将不起作用。

这完全取决于您的用例。鉴于这是一个程序员论坛,让我们考虑一下这个观点。

如果您的软件存储实际的互联网地址 - 服务器位置、网站访问者、复制/镜像或备份站点、Web 服务或数据库服务器等 - 那么这将是完全有效的。互联网上的任何机器都不会分配此地址,也不会解析为有效的连接。

另一方面,如果您正在编写防火墙或路由器固件,那么该地址确实具有特殊含义;默认路由、接受任何 IP 源/目的地、阻止所有 IP 源/目的地、陷入困境等,如其他人所述。但是,让我指出,如果您在这个级别上进行编码,您应该对网络协议有足够的了解,以便首先不需要问这个问题。

因此,我假设大多数查看此问题的人都属于第一类,并建议如果有某种原因,这是存储 null、空或丢失 IP 地址的完全有效的方式不能使用实际的 null 值。即使您忽略验证检查并且您的软件确实尝试连接到该 IP 地址,它也根本无法建立连接。

Lets look at the Question being asked here by the OP.

Is 0.0.0.0 a valid IP address?

Yes. This is technically a valid IP address, and the other answers describe many various uses of it (I am not going to repost wikipedia links here ... or maybe I am).

As such I believe paxdiablo's answer above is the most correct, but lets look at the context of your question as well.

I want my program to be able to store it as an indication that no address is in use, but this won't work if it's actually valid.

This entirely depends on your use case. Given that this is a programmers forum, lets consider that perspective.

If your software is storing actual internet addresses - server locations, visitors to your website, replication/mirror or backup sites, web service or database servers etc. - then this will be perfectly valid. No machine on the internet will ever have this address assigned, nor will it ever resolve to a valid connection.

If on the other hand you are writing firewall or router firmware, then this address does take on special meaning; default route, accept any IP source/destination, block all IP source/destination, fall-trough catch-all, etc. as outlined by everyone else. However, let me point out that if you are coding on this level you should have a good enough understanding of network protocols so as to not need to ask this question in the first place.

I am therefore going to assume that most people viewing this question fall into the first category, and suggest that this is a perfectly valid way of storing a null, empty or missing IP address, if there is some reason that an actual null value cannot be used. Even if you neglect validation checking and your software does try to connect to this IP address, it will simply not be able to make a connection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文