zoukankan      html  css  js  c++  java
  • python 获取主机名称和ip地址

    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
  • 相关阅读:
    副本集-Replica Sets
    SpringBoot整合SpringData MongoDB
    Auth认证
    Form
    flask一些插件
    SQLAlchemy
    session
    上下文
    flask路由
    Flask中间件
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11031485.html
Copyright © 2011-2022 走看看