0 votes
1 view
in Data Science by (18.3k points)

I am trying to construct the command which includes the variable containing IP addresses to the subprocess but the variable is not passed.

iplist

8.8.8.8

1.1.1.1

code

with open('iplist', 'r', encoding="utf-8") as f:

    data = f.read()

    print(data)

    cmd = ['./mmdbinspect', '--db', '/usr/local/var/GeoIP/GeoLite2-City.mmdb', '$data']

    result = subprocess.run(cmd, stdout=subprocess.PIPE)

    print(result.stdout)

output

8.8.8.8

1.1.1.1

2020/11/01 10:06:13 could not get records from db /usr/local/var/GeoIP/GeoLite2-City.mmdb: $data is not a valid IP address

b''

1 Answer

0 votes
by (36.8k points)

Something like

with open('iplist', 'r', encoding="utf-8") as ip_file:

    for ip in ip_file:

      cmd = ['./mmdbinspect', '--db', '/usr/local/var/GeoIP/GeoLite2-City.mmdb', ip.strip()]

      result = subprocess.run(cmd, stdout=subprocess.PIPE)

      print(result.stdout)

 Want to be a master in Data Science? Enroll in this Data Science Courses

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...