python2.7

#!/usr/bin/env python
# Python Network Programming Cookbook -- Chapter - 1
# This program is optimized for Python 2.7.
# It may run on any other version with/without modifications.

import socket


def print_machine_info():
    host_name = socket.gethostname()
    ip_address = socket.gethostbyname(host_name)
    print "Host name: %s" %host_name
    print "IP address: %s" %ip_address

if __name__ == '__main__':
    print_machine_info()

 输出

Host name: ubuntu
IP address: 127.0.1.1

 

相关文章:

  • 2021-09-17
  • 2021-11-30
  • 2022-02-10
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-09-12
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案