给redis发送消息的脚本

#!/usr/bin/env python3

import redis
from random import randint

pool=redis.ConnectionPool(host='127.0.0.1',port=6379,decode_responses=True)
red=redis.Redis(host='127.0.0.1',port=6379,decode_responses=True)

def random_ip():
        ip = []
        for x in range(4):
            ip.append(str(randint(0,255)))
        return '.'.join(ip)

def main():
    for num in range(1,50000):
        ip=random_ip()
        js = '{"clientIP": "'+ ip +'", "type": "country", "ipBlackSec":"3600"}'
        print(str(num) + ':\t' +js)
        with open('iplist.txt','a') as ip_list:
            ip_list.write(ip + "\n")
        red.publish('site:firewall',js)
if __name__ == '__main__':
    main()

相关文章:

  • 2022-01-10
  • 2021-08-24
  • 2021-06-27
  • 2021-12-26
  • 2021-05-31
  • 2021-06-19
  • 2021-12-05
  • 2022-01-19
猜你喜欢
  • 2021-12-15
  • 2022-01-17
  • 2022-01-04
  • 2021-11-28
  • 2022-01-10
  • 2021-12-29
  • 2021-12-06
相关资源
相似解决方案