One way you could do this would be using input
(python3) (or raw_input
(python2)) or specifying hostname as an argument to your script. You could get output from all by not specifying any hostname.
Assuming your hostnames are in a python list dnshostnames
:
input
:
hostname = input("specify hostname (blank for all)").strip()
if hostname:
if hostname in dnshostnames:
print("{} in host name list".format(hostname))
else:
print("Hostnames:\n\n","\n".join(dnshostnames)
or as argument to script:
import sys
if len(sys.argv<1):
#assuming hostname has no whitespace in name
if sys.argv[1] in dnshostnames:
print("{} in host name list".format(hostname))
else:
print("Hostnames:\n\n","\n".join(dnshostnames)
which would then be called as python myscript.py myhostname