Ejemplo n.º 1
0
    def task(self,req,threadname):
        print 'the ip is '+req
        ip=req
        jsondata=webtool.getLocationinfo(req)
        country,country_id,area,area_id,region,region_id,city,city_id,county,county_id,isp,isp_id=getlocationjsondata(jsondata)
        localtime=str(time.strftime("%Y-%m-%d %X", time.localtime()))
       
        
        insertdata=[]
        

        insertdata.append((ip,country,country_id,area,area_id,region,region_id,city,city_id,county,county_id,isp,isp_id,localtime))
                                         
        extra=' on duplicate key update  updatetime='+SQLTool.formatstring(localtime)+',country='+SQLTool.formatstring(country)+', country_id='+SQLTool.formatstring(country_id)+',area='+SQLTool.formatstring(area)+', area_id='+SQLTool.formatstring(area_id)+',region='+SQLTool.formatstring(region)+', region_id='+SQLTool.formatstring(region_id)+',city='+SQLTool.formatstring(city)+', city_id='+SQLTool.formatstring(city_id)+',county='+SQLTool.formatstring(county)+', county_id='+SQLTool.formatstring(county_id)+',isp='+SQLTool.formatstring(isp)+', isp_id='+SQLTool.formatstring(isp_id)

        sqldatawprk=[]
        dic={"table":self.config.iptable,"select_params":['ip','country','country_id','area','area_id','region','region_id','city','city_id','county','county_id','isp','isp_id','updatetime'],"insert_values":insertdata,"extra":extra}
        if self.islocalwork==0:
            tempdata={"func":'inserttableinfo_byparams',"dic":dic}
            jsondata=uploaditem.UploadData(url=self.webconfig.upload_ip_info,way='POST',params=tempdata)
            sqldatawprk.append(jsondata)
            self.uploadwork.add_work(sqldatawprk)
        else:
            
        
        
            tempwprk=Sqldata.SqlData('inserttableinfo_byparams',dic)
            sqldatawprk.append(tempwprk)
            self.sqlTool.add_work(sqldatawprk)
        
        time.sleep(0.1)
        ans=''
        return ans
Ejemplo n.º 2
0
    def task(self, ip, threadname):
        print 'getLocationTool::task() ip location do ......the ip is ' + ip
        jsondata = webtool.getLocationinfo(
            ip)  #使用ip.taobao.com获取该ip对应的信息,返回一个json结构的字典
        country, country_id, area, area_id, region, region_id, city, city_id, county, county_id, isp, isp_id = getlocationjsondata(
            jsondata)
        localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
        insertdata = []
        insertdata.append(
            (ip, country, country_id, area, area_id, region, region_id, city,
             city_id, county, county_id, isp, isp_id, localtime))

        extra = ' on duplicate key update updatetime=' + SQLTool.formatstring(
            localtime) + ',country=' + SQLTool.formatstring(
                country) + ', country_id=' + SQLTool.formatstring(
                    country_id) + ',area=' + SQLTool.formatstring(
                        area) + ', area_id=' + SQLTool.formatstring(
                            area_id) + ',region=' + SQLTool.formatstring(
                                region
                            ) + ', region_id=' + SQLTool.formatstring(
                                region_id) + ',city=' + SQLTool.formatstring(
                                    city
                                ) + ', city_id=' + SQLTool.formatstring(
                                    city_id
                                ) + ',county=' + SQLTool.formatstring(
                                    county
                                ) + ', county_id=' + SQLTool.formatstring(
                                    county_id
                                ) + ',isp=' + SQLTool.formatstring(
                                    isp) + ', isp_id=' + SQLTool.formatstring(
                                        isp_id)

        sqldatawork = []
        dic = {
            "table":
            self.config.iptable,
            "select_params": [
                'ip', 'country', 'country_id', 'area', 'area_id', 'region',
                'region_id', 'city', 'city_id', 'county', 'county_id', 'isp',
                'isp_id', 'updatetime'
            ],
            "insert_values":
            insertdata,
            "extra":
            extra
        }
        # 和之前的手工写入数据库操作一样
        tempwork = Sqldata.SqlData('inserttableinfo_byparams', dic)
        sqldatawork.append(tempwork)
        self.sqlTool.add_work(sqldatawork)
        del insertdata
        time.sleep(0.2)
        ans = ''
        return ans
Ejemplo n.º 3
0
    def task(self, req, threadname):
        print 'ip location do ......the ip is ' + req
        ip = req
        jsondata = webtool.getLocationinfo(req)
        country, country_id, area, area_id, region, region_id, city, city_id, county, county_id, isp, isp_id = getlocationjsondata(
            jsondata)
        localtime = str(time.strftime("%Y-%m-%d %X", time.localtime()))
        insertdata = []

        insertdata.append(
            (ip, country, country_id, area, area_id, region, region_id, city,
             city_id, county, county_id, isp, isp_id, localtime))

        extra = ' on duplicate key update  updatetime=' + SQLTool.formatstring(
            localtime) + ',country=' + SQLTool.formatstring(
                country) + ', country_id=' + SQLTool.formatstring(
                    country_id) + ',area=' + SQLTool.formatstring(
                        area) + ', area_id=' + SQLTool.formatstring(
                            area_id) + ',region=' + SQLTool.formatstring(
                                region
                            ) + ', region_id=' + SQLTool.formatstring(
                                region_id) + ',city=' + SQLTool.formatstring(
                                    city
                                ) + ', city_id=' + SQLTool.formatstring(
                                    city_id
                                ) + ',county=' + SQLTool.formatstring(
                                    county
                                ) + ', county_id=' + SQLTool.formatstring(
                                    county_id
                                ) + ',isp=' + SQLTool.formatstring(
                                    isp) + ', isp_id=' + SQLTool.formatstring(
                                        isp_id)

        sqldatawprk = []
        dic = {
            "table":
            self.config.iptable,
            "select_params": [
                'ip', 'country', 'country_id', 'area', 'area_id', 'region',
                'region_id', 'city', 'city_id', 'county', 'county_id', 'isp',
                'isp_id', 'updatetime'
            ],
            "insert_values":
            insertdata,
            "extra":
            extra
        }
        tempwprk = Sqldata.SqlData('inserttableinfo_byparams', dic)
        sqldatawprk.append(tempwprk)
        self.sqlTool.add_work(sqldatawprk)

        time.sleep(0.1)
        ans = ''
        return ans
Ejemplo n.º 4
0
def test():
    jsondata=webtool.getLocationinfo('123.123.123.123')
    if jsondata.get('code','1')==0:
        country=jsondata['data'].get('country','0')
        country_id=str(jsondata['data'].get('country_id','0'))
        area=jsondata['data'].get('area','0')
        area_id=str(jsondata['data'].get('area_id','0'))
        region=jsondata['data'].get('region','0')
        region_id=str(jsondata['data'].get('region_id','0'))
        city=jsondata['data'].get('city','0')
        city_id=str(jsondata['data'].get('city_id','0'))
        county=jsondata['data'].get('county','0')
        county_id=str(jsondata['data'].get('county_id','0'))
        isp=jsondata['data'].get('isp','0')
        isp_id=str(jsondata['data'].get('isp_id','0'))
        return country,country_id,area,area_id,region,region_id,city,city_id,county,county_id,isp,isp_id