[英]Read IP address from text file to IPTABLES
目前,我正在使用ufw通过键入手动添加IP规则
sudo ufw allow from (my ip address)
我已经通过从数据库中执行一些脚本调用来检索了客户端IP的IP地址,并将其保存到.txt文件中。
这就是我得到的价值
ipaddress
10.1.100.90
10.1.100.91
是否可以读取.txt文件中的IP地址并将其保存到规则中,而不是手动输入?
您可以在python中编写一个简单的脚本,该脚本可以读取包含IP地址列表的文本文件,然后在每个IP地址上依次执行Linux命令。简单指南Python执行Unix / Linux命令示例
您可以使用bash
脚本,如下所示
#!/bin/bash
{
# Skip the header line containing 'name ipaddress'
read skipLine;
# Read the rest of the lines till end of the file
while IFS= read -r name IP
do
# All the IP's are stored in the variable $IP. Use it
# however you want
printf "%s %s\n" "$name" "$IP"
# To print only the IPs, do
# printf "%s\n" "$IP"
done
} <IPFile
# IPFile - Input file name containing IP addresses. Replace it with your file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.