hello.py

Posted on Posted in python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
import time

def get_time():
    return time.strftime('%Y-%m-%d',time.localtime(time.time()))

def get_host_ip():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 80))
        ip = s.getsockname()[0]    
    finally:
        s.close()

    return ip
print(get_time())
print(get_host_ip())
» 转载请注明来源:若我若鱼 » hello.py

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × four =