目前我正在使用 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