gethostbyname

process-local override of name resolution?

喜欢而已 提交于 2019-12-11 01:59:29
问题 I have test code that I want to have a couple of hostnames resolve to the loopback while testing. When deployed, this code will use the normal system name resolution as appropriate. Test and deployment host are recent linux distros (SLES11SP1, e.g.). I'd like to override hostname resolution for a single process, without being superuser. Is there a way to manipulate the nsswitch / hosts behavior in such a narrow fashion? Yes, of course I could override the hostnames themselves, but I prefer

gethostbyname dual network interfaces, select which one to use

旧时模样 提交于 2019-12-10 18:56:27
问题 I have a c-program that needs to connect to a server and send a tcp payload and wait for the response. This works well for normal use but since I have two different network interfaces, let us call them if0 and if1 on the computer running the program, sometimes one of the network interfaces are not able to forward the traffic. This is a fact that I cannot change unfortunately. To handle this gracefully since the OS cannot help me route the data to the correct interface, I send the payload

gethostbyname() processes resolving consistently even from different threads?

老子叫甜甜 提交于 2019-12-10 10:29:46
问题 I conducted an experiment with DNS resolving by gethostbyname() from different threads. I turned off network link and ran program below. And output was like this gethostbyname started at 1411234734 gethostbyname started at 1411234734 gethostbyname started at 1411234734 gethostbyname finished at 1411234774 gethostbyname finished at 1411234814 gethostbyname finished at 1411234854 gethostbyname() started at the same time, but finished one by one with 40 sec timeout. Then i experemented with

Asynchronous address resolution in winsock?

て烟熏妆下的殇ゞ 提交于 2019-12-09 18:16:49
问题 Looking into asynchronous address resolution in winsock it seems that the only two options are either to use the blocking gethostbyname on a seperate thread, or use WSAAsyncGetHostByName . The latter is designed for some reason to work with window messages, instead of overlapped operations and completion ports/routines. Is there any version of gethostbyname that works asynchronously with overlapped operations in a similiar manner to the rest of the winsock API? 回答1: Unfortunately there isn't

How to flush cache for socket.gethostbyname response?

陌路散爱 提交于 2019-12-09 17:23:25
问题 Anyone run into this before: After updating DNS records..I do a dig for 'test.somedomain.com' I get 167.69.143.234, however when I do a socket.gethostbyname('test.somedomain.com') I get 167.69.6.234. I'm guessing socket is still using cache...how do I clear it ? or flush it? My code is very simple: Linux Termianl dig test.somedomain.com Python: import socket socket.gethostbyname('test.somedomain.com') It should be returning the 167.69.143.234 address as that is the updated one in DNS. 回答1:

Domain name to IPv6 address in Perl

我与影子孤独终老i 提交于 2019-12-08 07:39:32
问题 I have the following Perl code to translate domain name to IP address. It works fine in IPv4. $host = "example.com"; $ip_address = join('.', unpack('C4',(gethostbyname($host))[4])); However, it does not work if it is an IPv6 only domain name such as "ipv6.google.com". How can I get one line of code (prefer CORE library) to get IPv6 IP address? $host = "ipv6.google.com"; $ip_address = ??? 回答1: In 5.14 and above, you can use the core Socket: use 5.014; use warnings; use Socket (); # protocol

php获取本机ip

六眼飞鱼酱① 提交于 2019-12-05 09:19:34
最近在写个东西时,需要获取本机的IP,但是由于php本身不带这样的功能,在网上找了好久也没有一个好办法,突然想到一个好办法,如下代码 <?=gethostbyname($_ENV['COMPUTERNAME'])?>www.cdxsxbx.com 其中$_ENV['COMPUTERNAME']是获取本机的名字,而gethostbyname()则是获取域名的IP,这样就可以完美地获取本机IP。 来源: https://www.cnblogs.com/fuoryao/p/11918754.html

Alternative to gethostbyname

强颜欢笑 提交于 2019-12-05 07:50:58
I can't use gethostbyname to grab a host's IP address, it is a deprecated function that only works 10% of the fricken' time on Windows! I can't find any adequate resources on other ways to find a host's IP address using other functions (MSDN recommended getaddrinfo but that doesn't seem like what I want.) Actually, getaddrinfo is what you want. It's just a long-winded way to do it, not to mention the fact that sometimes multiple IP addresses are found (e.g. one IPv4 address and one IPv6 address). I'd recommend looking at Beej's Guide to Network Programming , specifically getaddrinfo . You can

getaddrinfo函数返回No such file or directory的分析

岁酱吖の 提交于 2019-12-05 07:09:18
在项目中实现NTP功能模块时,为了更好的兼容和更小的警告,将gethostbyname函数用getaddrinfo函数进行了替代,可是在开发板上运行时却遇到了这个错误: getaddrinfo fail for host time.windows.com:System error error:No such file or directory 然而同样的代码程序在PC上运行是正确的。可以确定是开发板上的文件系统环境缺少某个与网络相关的配置文件导致getaddrinfo系统调用执行失败,问题在于是哪一个文件,怎么来找到它?答案是使用strace工具在追踪getaddrinfo在PC上执行是的文件访问记录,从而找出缺少的配置文件。 为了减少干扰,使用一个简单的test程序来进行分析,使用如下命令得到追踪记录: # strace -e trace=file -o 2.strace ./test_getaddrinfo 追踪记录文件信息如下(为了保持strace文件的语法高亮,这里使用图片): 滤掉程序执行涉及的动态库链接缓存之类的文件(因为程序运行起来了),就只剩下三个文件了:/etc/host.conf /etc/hosts /etc/resolv.conf. /etc/resolv.conf文件是域名解析服务器列表的参数文件,实现域名解析,必须设置域名服务器的地址,开发板上已经配置了

Python attribute error: type object '_socketobject' has no attribute 'gethostbyname'

那年仲夏 提交于 2019-12-04 11:05:38
问题 I am trying to do this in my program: dest = socket.gethostbyname(host) I have included the line: from socket import * in the beginning of the file. I am getting this error: AttributeError: type object '_socketobject' has no attribute 'gethostbyname' I am running Vista 64bit. Could there be a problem with my OS? I have turned down my firewall and everything. 回答1: You shoulod either use import socket dest = socket.gethostbyname(host) or use from socket import * dest = gethostbyname(host) Note: