marc:linux:chatgtp
This is an old revision of the document!
CHATGTP VOER
Extract banned ip addresses
Write a bash script that will do the following: Using the command "sudo fail2ban-client status sshd", from the output, get the banned ip addresses and sort them into the file "banned_ips.txt" displaying 1 ip address per line.
Answer from chatgtp needs some work:
#!/bin/bash
# Get the banned IP addresses using the fail2ban-client command
banned_ips=$(sudo fail2ban-client status sshd | grep "Banned IP list" | awk '{print $NF}')
# Sort the banned IP addresses and store them in a file
echo "$banned_ips" | sort | uniq > banned_ips.txt
This however only shows last ip address
marc/linux/chatgtp.1676020012.txt.gz · Last modified: (external edit)
