网站防篡改脚本 网页防篡改脚本

这个脚本用于监控网站源码是否有变更.当脚本开始运行时的源码和现在的源码进行对比,如有变化就会进行播放歌曲.后 期再加入邮箱提醒功能…或者利用itchat微信机器人进行微信推送

运行前请安装pygame模块,命令如下:

pip install pygame

如果pip安装pygame比较慢,可以用IDM下载会快一点

该工具目前适用kali Linux系统,其他系统自行测试,出问题概不负责,请先在本地进行测试.只针对于能联网的网站/系统,如果网站不能联网,请修改播放音乐地址为本地即可.

# coding=utf-8
'''
Author:SholWay.
Date:2019.10.01
For:检测网站内容是否有改动,若有则会播放音乐.
'''
import pygame
import time
import os
import sys
website = "http://www.baidu.com/" # 这边更改要监控的网页

def checkNetwork(saveType):
    if(os.system("curl {}>{}".format(website,saveType))):
        print ("Network Connect Error!!!")
        sys.exit()
    
def getMusic():
    if(os.system("curl https://rl01-sycdn.kuwo.cn/89bb4d4be00d0eed1482f0f88658a26b/5d935a67/resource/n3/1/49/4211576901.mp3 --output alert.mp3")):
        print ("Download alert music failure!Check the source or your network before use.")

def playMusic():
    pygame.mixer.init()
    pygame.mixer.music.load('alert.mp3')
    pygame.mixer.music.play(start=0.0)
    time.sleep(1800)

def getPageSource():
    checkNetwork(saveType="newCode")

def main():
    while 1:
        print (50*"-")
        getPageSource() 
        print ('Get web source code done!')
        if ((os.system("diff originalCode newCode"))==0):
            print ("Checked page code didn't change...")
            print (50*"-")
            time.sleep(20)
        else:
            print (50*"--")
            print ("\033[5;31m Warning: Webpage source has been changed! Check it now please!!! \033[0m")
            print ("")
            playMusic()
            

if __name__=='__main__':
    try:
        checkNetwork(saveType='originalCode')
        getMusic()
        main()
    except Exception,err:
        print (err)
        sys.exit()

from

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用*标注