-1

Currently I am using ufw to manually add the ip rules by typing

sudo ufw allow from (my ip address)

I have retrieve the ip address of my client ip by doing some script calling from my database and save it to a .txt file.

this is the value i get

  ipaddress
 10.1.100.90
 10.1.100.91

Is it possible to read the ip address in the .txt file and save it to the rule instead of typing manually?

Fouzy
  • 125
  • 1
  • 1
  • 7
  • You are not supposed to edit question requirements after posting it once, and answers have been provided – Inian Feb 02 '17 at 09:30

2 Answers2

0

You can write a simple script in python that can read text file containing IP address list and then execute Linux command one by one on each IP address.A simple guide Python Execute Unix / Linux Command Examples

  • I need some examples. I have never used python before and Iam new to linux the command. – Fouzy Feb 02 '17 at 08:28
  • Please refer to the question. http://stackoverflow.com/questions/14676265/how-to-read-text-file-into-a-list-or-array-with-python and then https://www.cyberciti.biz/faq/python-execute-unix-linux-command-examples/ – Kashif Sohail EF Feb 02 '17 at 08:30
0

You could use a bash script like something below

#!/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
Inian
  • 80,270
  • 14
  • 142
  • 161