美文网首页
python获取一些本机信息

python获取一些本机信息

作者: 家琦的三亩地 | 来源:发表于2016-10-12 10:18 被阅读0次

    Python加中文注释,第一行加 -*- coding: utf-8 -*

    #python获取本机mac
    import uuid
    def get_mac_address():
        mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
        return ":".join([mac[e:e+2] for e in range(0,11,2)])
    print get_mac_address()
    
    #获取本机电脑名
    import socket
    myname = socket.getfqdn(socket.gethostname(  ))
    #获取本机ip
    myaddr = socket.gethostbyname(myname)
    print myname
    print myaddr
    
    #获取当前用户
    import os
    import  getpass
    UserNmae1 = os.environ['USERNAME']
    print  UserNmae1
    UserNmae2 = getpass.getuser()
    print  UserNmae2
    
    #获取当前时间
    import datetime
    # Get a datetime object
    now = datetime.datetime.now()
    # General functions
    print "Year: %d" % now.year
    print "Month: %d" % now.month
    print "Day: %d" % now.day
    print "Weekday: %d" % now.weekday()
    # Day of week Monday = 0, Sunday = 6
    print "Hour: %d" % now.hour
    print "Minute: %d" % now.minute
    print "Second: %d" % now.second
    print "Microsecond: %d" % now.microsecond
    # ISO Functions
    print "ISO Weekday: %d" % now.isoweekday()
    # Day of week Monday = 1, Sunday = 7
    print "ISO Format: %s" % now.isoformat()
    # ISO format, e.g. 2010-12-24T07:10:52.458593
    print "ISO Calendar: %s" % str(now.isocalendar())
    # Tuple of (ISO year, ISO week number, ISO weekday)
    # Formatted date
    print now.strftime("%Y/%m/%d")
    

    相关文章

      网友评论

          本文标题:python获取一些本机信息

          本文链接:https://www.haomeiwen.com/subject/yeciyttx.html