python 脚本之 获取远程主机的hostname

Posted 划得戳

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 脚本之 获取远程主机的hostname相关的知识,希望对你有一定的参考价值。

import sys, socket
try:
  result = socket.gethostbyaddr("查询的IP") #查询完后获得一个元组
  print (result)  #打印元组 例如:(‘mon-node1‘, [], [‘10.101.0.95‘])

  for item in result[2]:
    print " " + item

  

 

以上是关于python 脚本之 获取远程主机的hostname的主要内容,如果未能解决你的问题,请参考以下文章