How to get the user set computer name using python in MacOS Sierra/High Sierra

China☆狼群 提交于 2019-12-04 09:56:01

I can confirm this bug and also the workaround with the note that it would not become effective right away, no restart necessary but DNS cache needs to expire (or be expired) to fully be effective.

I experience the same issue which affects any non-fqdn resolution, not only the local machine name. For example nslookup or ping seems to work perfectly while only python socket.getfqdn() and socket.gethostbyname() seem to be brokened. My system had both IPv4 and IPv6 stack, which may be related to the issue.

So workaround looks like:

sudo scutil --set HostName `hostname`

It would be essential for hostname to return a FQDN in order for this to work.

In my case it was like foo.lan, and after doing this python started to be able resolve names like foo.lab or bar.lan

Because OS native tools are not affected by this, I ended up creating a Python bug related to MacOS, as we should not be forced to use the workaround above to make it work.

https://bugs.python.org/issue35164 <-- lets follow up here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!