麒麟, 发表于 2019-12-4 04:19

关于py脚本

# -- coding: utf-8 --

import urllib
import urllib2
import json
import os
import time


def isok(line):
    requrl = "http://lj.52jcc.cc/wxjc.php"
    formate = {
      'type':1,
      'key': 'aqtnUfZ31AAnMqSM45JmCrhJslZNAIvM',
      'ym': line
    }
    header = {
      'X-Requested-With':'XMLHttpRequest'
    }
    try:
      data = urllib.urlencode(formate)
      request = urllib2.Request(requrl, data,header)
      response = urllib2.urlopen(request)
      dd=response.read()
      #print(dd)
      js = json.loads(dd)
      print(js)
      status = js['code']['status']
      if int(status) == 2:
            return True
      else:
            return False
    except Exception as e:
      print(e)
      return True


i = 0
sleeptime = 2
prevtime = 0
end = True
while end:
    # 读取文件URL列表
    urllist_path = '/www/wwwroot/47.105.192.187/urllist1.txt'
    url_path = '/www/wwwroot/47.105.192.187/url1.txt'
    with open(urllist_path, 'r') as f:
      lines = f.readlines()

    #print(lines)
    with open(urllist_path, 'w') as fw:
      flag = False
      end = False
      for line in lines:
            #print(line)
            if not flag:
                if '##' in line:
                  fw.write(line)
                  continue
                line = line.strip()
                if isok(line):
                  # 写入新文件
                  fu = open(url_path, 'w+')
                  oldurl = fu.readline()
                  if oldurl == line:
                        print("新旧一致")
                  else:
                        fu.write(line)
                        fu.close()
                        # 记录时间放置更换域名后快速再死。
                        prevtime = time.time()
                        print("成功处理" + line)
                  fw.write(line + '\n')
                  flag = True

                else:
                  d = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
                  fw.write(
                        line + '   ##domain is broken,datetime:' + d + '\n')
                  print("域名异常"+line)
            else:
                fw.write(line)

    fw.close()

    if time.time() - prevtime < 300:
      sleeptime = 300
    else:
      sleeptime = 15
    #time.sleep(sleeptime)




这是我以前用的py脚本的检测接口,现在没有用了换接口地址了
http://www.maoapi.cn/wxymjc?url_long=域名
返回信息 {"status":0,"msg":"域名被封"}
{"status":0,"msg":"域名被封"}{"status":1,"msg":"域名正常"}
0是被封1是正常
py脚本现在该怎么改啊
页: [1]
查看完整版本: 关于py脚本