#获取服务器服务器ip模块

#aiwaly-pymo-0001-GetIpforwin7
#get window ip
#获取服务器服务器ip模块
def AW_GetIpforwin7():
        import socket 
        hostname = socket.gethostname() 
        IPinfo = socket.gethostbyname_ex(hostname)
        return   IPinfo      

IPinfo=AW_GetIpforwin7()
print "{\"Host\":\"%s\",\"ip\":\"%s\"}" %(IPinfo[0],IPinfo[2])
#aiwaly-pymo-0002-ip2long
def awmo0002_ip2long (ip):
    "将点分十进制 IP 地址转换成无符号的长整数"
    import struct,socket
    return struct.unpack("!I", socket.inet_aton(ip))[0]
#aiwaly-pymo-0003-ip2long
def awmo0003_long2ip (lint):
    "将无符号长整形转换为点分十进制 IP 地址形式"
    import struct,socket
    return socket.inet_ntoa(struct.pack("!I", lint))
import time
#aiwaly-pymo-0004-getCurrentTime
#获取当前时间
def awmo0004_getCurrentTime(self):
    return time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time()))
import time
#aiwaly-pymo-0005-getCurrentTime
#获取当前日期
def awmo0005_getCurrentDate(self):
    return time.strftime('%Y-%m-%d',time.localtime(time.time()))
#aiwaly-pymo-0006-getCurrentDate    
#获取N天前时间
def awmo0006_getCurrentDate(self,Nday):   
    reture time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time()- 86400*Nday ) )
import hashlib
#aiwaly-pymo-0007-get_md5_value 
#md5 算法
def awmo0007_get_md5_value(src):
    myMd5 = hashlib.md5()
    myMd5.update(src)
    myMd5_Digest = myMd5.hexdigest()
    return myMd5_Digest
def awmo0008_downloadfile(url,filename):
    #aiwaly-pymo-0008-downloadfile
    "下载指定url到指定文件"
    import urllib2

    #"url = 'http://www.pythontab.com/test/demo.zip'
    #filename  is  save filename and path
    try:
        f = urllib2.urlopen(url, timeout=10) 
        data = f.read() 
        with open(filename, "wb") as code:     
             code.write(data)
        f.close
        return  True 

    except:
        return  False
#文件下载hash目录存储#aiwaly-pymo-0009-wget_file_hash
def awmo0009_wget_file_hash(subjectname ,url ,imgfilename):   
        import sys ,os 
        ##判断临时目录是否存在
        hashdir=get_md5_value(imgfilename)
        subjectpah=sys.path[0]+'/../../sources/' +subjectname + "/" +hashdir[0] + hashdir[1] + "/"+hashdir[1] + hashdir[2] + "/"
        print subjectpah        
        if not os.path.isdir(subjectpah):
                 os.makedirs(subjectpah)

        print downloadfile(url,subjectpah + imgfilename)
#使用样例
#wget_file_hash("subjectdir" ,"http://www.duba.com/static/v2/images/blank.gif" ,"blank.gif")
文档更新时间: 2019-06-16 20:50   作者:月影鹏鹏