I have a bash script which goes out,does some DNS queries and returns an IP address value which I assign as a variable $external
I want to take this variable from the bash script and feed it into python and do some subnet intelligence but I'm not sure how to handle the data after this and pass it back to bash.
I can see that the $external variable is being passed from bash into python ok but this is where I'm not sure what to do next. (thanks Farhan.K for assisting me with what I have already)
python3 <<END
import ipaddress
ipsub = {"10.10.10.0/24": "Firewall-Denver", "10.10.20.0/25": "FirewallNewYork"}
iplist = [$external]
ipfirewall = []
for i in ipsub:
for j in iplist:
if ipaddress.ip_address(j) in ipaddress.ip_network(i):
ipfirewall.append([j,ipsub[i]])
END
The following would write it to a file:
with open('output.txt', 'w') as file:
file.writelines('\t'.join(i) + '\n' for i in ipfirewall)
But how to I pass it back to bash in the same format?
Thanks in advance for your advice and assitance.