问题标签 [gethostbyname]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
php - php gethostbyname() 在 Windows 上非常慢
我正在尝试实现多线程脚本(php7+phtreads v3)来获取有关大量域的信息。但是,最重要的是找出域的IP。我发现 gethostbyname() 工作很慢,这是代码的瓶颈。有没有办法以某种方式提高性能?谢谢你。
c++ - 将字符串地址转换为 IP 地址以进行套接字调用
以下客户端代码正在尝试准备发送 UDP 数据报。但是,地址设置不正确,因此发送无处可去。
我得到的错误是:sendto:无效或不完整的多字节或宽字符
我假设这是在谈论地址,而不是正在发送的数据。
任何人都可以识别问题吗?
电话是:
这是调试器中的 addrinfo 对象:
在我看来,那里没有正确的地址,但一路上没有一个电话失败。
c - 使用 gethostbyname 的 DNS
我在 C 中执行以下操作以从主机名获取 IP 地址。它打印IP是?*?,所以它不起作用。我究竟做错了什么?
c - Resolve FQDN but not necessarily canonical name with getaddrinfo()
Good evening, folks.
Is it possible to use getaddrinfo()
/getnameinfo()
to resolve non-FQDN names to their FQDN versions, but without necessarily going all the way down to the canonical name, in a way similar to that of gethostbyname()
?
To clarify my question, let me try to describe my use scenario, below.
Suppose that my company,
example.com
, has several internal departments with (semi-)autonomous DNS zone administration, each published asdeptX.example.com
,deptY.example.com
etc.Every department's computer is configured to have a DNS suffix search list in a form like
p>Department X offers a service publicly known as hosted by
host1.deptX.example.com
, but that name is actually an alias tointernal-unique-name.cloud.example.org
.The internal name is (almost) never published or known by any client anywhere (unless, of course, that client cares to look at the DNS response).
In many (possibly most) cases, administrators configure their clients to use a shorter, partial name
host1.deptX
, relying on the DNS suffix search list to resolve the full namehost1.deptX.example.com
. (Notice that it works everywhere, not just in Department X.)Some administrator (AKA me) has to uniquely identify published services everywhere into a summarized list, classified by department, collapsing different published names referring to same host (such as the partial names and corresponding FQDN) into a single entry.
In the past, when gethostbyname()
was the only option, I used to feed it with a partial name such as "host1.deptX"
, and the h_name
field in the response would give me the FQ, but not canonical, DN "host1.deptX.example.com"
, which was very good for me.
Since gethostbyname()
and gethostbyaddr()
are officially obsolete for quite some time, I thought that I should move to getaddrinfo()
and getnameinfo()
, especially with new implementations.
However, I didn't find an equivalent to struct hostent
's h_name
field. The closest, as it seems to me, is struct addrinfo
's ai_canonname
, which only gets filled when I request to resolve the canonical name, with the AI_CANONNAME
flag. If I do that with the scenario above, the resulting name would however be internal-unique-name.cloud.example.org
, which is not what I want.
Am I missing anything, and maybe misusing getaddrinfo()
? Is there a way to have that function give me the answer that I need?
IMO, those partial names should have been avoided from the beginning. OTOH, it would be impractical to try to fix them now (especially in departments other than my own), so that is not really an option.
I am certainly able to switch further from getaddrinfo()
to libresolv's res_query()
and its siblings, but I would like to avoid that for a number of reasons, including the ability to resolve local names (e.g. /etc/hosts
), use local name caches (e.g. ncsd
on UNIX) and names that are published on alternate directories, such as LDAP and NIS, but absent from the DNS (a rare, but definitely extant situation).
EDIT: I tested further, and noticed that I made a mistake above. I was under the impression that
struct hostent
'sh_name
would always just append the short name's corresponding FQDN, but such behavior was only happening with names that were in the local database (/etc/hosts
, which was being read before any attempt to consult DNS) and for which the FQDN was the first entry in the line. For general, DNS-resolved names,h_name
gets filled with the canonical name, and the non-canonical FQDN only appears in list pointed to by theh_aliases
field.So
struct hostent
'sh_name
is actually equivalent tostruct addrinfo
'sai_canonname
, with the behavior difference thatgethostbyname()
apparently always makes its version point to some data, whilegetaddrinfo()
only usesai_canonname
if explicitly commanded by the option flag.OTOH,
struct addrinfo
doesn't have anything like a pointer to list of known aliases, that I can check against to figure out what department the host belongs to.In the end, I think I will stick to
gethostbyname()
for a little while, at least for the current tool.
php - 当名称作为变量而不是字符串文字传入时,PHP gethostbyname() 返回名称而不是 IP
当名称作为变量而不是字符串文字传入时,PHP gethostbyname() 返回名称而不是 IP
我在一些有价值的讨论中看到了类似的问题,但没有任何问题。
如果我将一个变量说 $domain 传递给 gethostbyname() 其中 $domain 是由 foreach 循环创建的字符串值,则返回值始终正是我输入的值 - 例如,如果 $domain =="google.com " 返回值为 google.com。使用字符串文字调用相同的函数 gethostbyname() 我得到了 IP 地址。gethostbyname('google.com')
这是一个已知的错误?有解决方法吗?我将不胜感激任何帮助。
谢谢
此代码失败 - 为结果生成 $url 的值:
第二组代码两次给出正确的 IP 地址($this->domainNames 中的每个值一次:
解决方案:事实证明,这导致我的变量中有一些草率的空间,这些空间在创建我的 $this->domainNames 数组值时使用修剪修复。
c++ - 为什么 gethostbyname() 会间歇性地为主机名提供 HOST_NOT_FOUND?
在 Mac OS X El Capitan 上,我正在运行一个 C++ 应用程序,该应用程序调用gethostbyname()
并有时传递与当前机器匹配的参数字符串:
这通常有效,但是,在极少数情况下,我会得到一个NULL
结果并h_errno
设置为HOST_NOT_FOUND
.
这是一个已知的问题?我的应用程序如何从中恢复?我想重试它成功的希望,但是对于当前机器的名称,我如何区分真正的主机未找到失败和这个暂时的失败?这种失败可能会持续多长时间,是什么原因造成的?
c++ - gethostbyname c++ 的问题
我用 C++ 编写了这段代码来连接服务器,但是每次我尝试“gethostbyname”时,该值都是空的(或者优化掉并且不可用)。
我已经尝试将 hostent 作为 volatile 但仍然给出 null 。有没有其他方法可以使这项工作?我也试过优化禁用但一直给null。
php - 执行 gethostbyname 最多 1 秒
当我这样做时:
它在不到 1 秒的时间内打印出 IP。
如果我尝试对不存在的域做同样的事情:
它尝试获取 IP 大约 7-8 秒,然后失败并改为打印域。
我想要实现的是gethostbyname
在 1 秒后以某种方式打破,因为我知道这意味着该域不存在。我有一个很大的域列表,所以我不能为每个无法访问的域等待 7-8 秒。我想停下来移动到下一个。
有什么办法可以做到这一点?
c - C 上的 Memcpy 和 hostent 结构
所以gethostbyaddr()
返回一个hostent
.
理论上,memcpy
我们不能将这个结构复制到另一个hostent
,因为h_aliases
and h_addr_list
。
所以我测试了在 C 上做一段代码。
代码的输出是:
正如你所看到的,同样的东西被打印了两次。它不应该第二次打印与Apple相关的东西吗?因为当我这样做时,memcpy
我复制了h_aliases
和h_addr_list
的指针dest struct
。
c - C中的“未知主机”错误
当我编写 twitter 控制台应用程序时,我遇到了 C 函数 gethostbyname() 的问题。Twitter API 提供连接到https://api.twitter.com/oauth2/token,但是当我尝试通过该函数获取 IP 时,它返回 NULL。Curl 可以很好地解析 URL,我认为 DNS 没有问题。连接的代码与我尝试过的相同,但也无法正常工作。
PS也许我的问题很明显,但是我浪费了至少7个小时,没有任何代码更改,只是试图找到答案。