LoginSignup
3
1

More than 3 years have passed since last update.

Centos7 firewalld の拒否リストを登録するやーつ

Posted at

とりあえずコマンドを毎回打つのが面倒なので...

とりあえずコマンドを毎回打つのが面倒なのとやっつけ作ったw
...Centos7 firewalld の拒否リストを登録するやーつ。

補足説明

  • 作り込み度 ★
  • zoneの作成は、dropという名称のみ
  • 使用方法は、権限付与した後、./ip_ban.pyで起動して、whois {IP}で得た情報を元に使用する
  • コマンドは、プレフィックスを含めた形式、または無しの直IPアドレスをinputする。 下の方に入力例がある。
ip_ban.py
#!/bin/python3.7
# -*- coding: utf-8 -*-
import subprocess
def banner(IP):
    cmd = f'firewall-cmd --zone=drop --permanent --add-source={IP}'
    r = subprocess.check_output(cmd.split())
    er = r.decode('utf-8')
    print(f'{er}Next IP...')

def reload():
    cmd = 'firewall-cmd --reload'
    r = subprocess.check_output(cmd.split())
    er = r.decode('utf-8')
    print(f'{er}')

if __name__ == "__main__":
    print('Hi! Welcome to IP BANNEEEER!')
    while True:
        ip = input('BAN IPaddress >>> ')
        if ip == 'end':
            reload()
            print('IP BANNER Shutdown...')
            break
        try:
            banner(ip)
        except:
            import sys
            print(f'{sys.exc_info()}')


example
Hi! Welcome to IP BANNEEEER!
BAN IPaddress >>> **.**.0.0/16 # or ***.***.***.***

課題

  • 拒否以外のその他コマンドにも対応したい。
  • そもそもファイル名など色々と名前がダサい...からかっこよく決めたいw
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1