有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在主机名中是否支持下划线?

在我的unix虚拟机中,我可以在/etc/hosts中提供以下条目 ABC_XYZ_主机名。美国广播公司。com 15.115.112.**在那之后,我可以成功地“ping ABC_XYZ_HOSTNAME.abc.com”。但我的密码在

InetAddresses.forString(ip)

除此之外,具有IP字符串文字的IllegalArgumentException无效

所以问题是,主机名是否支持下划线或其他错误


共 (1) 个答案

  1. # 1 楼答案

    您不能将DNS名称与InetAddresses.forString一起使用。此方法的javadoc表示:

    Returns the InetAddress having the given string representation.

    This deliberately avoids all nameservice lookups (e.g. no DNS).

    Parameters: ipString - String containing an IPv4 or IPv6 string literal, e.g. "192.168.0.1" or "2001:db8::1"

    DNS名称不是有效值

    对于DNS lookup of your address,您应该使用

    InetAddress.getByName(host)