I learned and code below which gives the Hostnames and Its IP address by the reading the hostname from the "mylabList.txt" file, Now i am looking the way to print the output in a pretty Human readable from Like Column header at the top of each and then the name (Below that)..
Is there way to set width between columns while printing...
#!/usr/bin/python
import sys
import socket
with open("mylabList.txt", 'r') as f:
for host in f:
print("{0[0]}\t{0[2][0]}".format(socket.gethostbyname_ex(host.rstrip())))
Current output is Like:
mylab1.example.com 172.10.1.1
mylab2.example.com 172.10.1.2
mylab3.example.com 172.10.1.3
mylab4.example.com 122.10.1.4
Expected Output is:
Server Name IP ADDRESS
===================================
mylab1.example.com 172.10.1.1
mylab2.example.com 172.10.1.2
mylab3.example.com 172.10.1.3
mylab4.example.com 122.10.1.4
Just a note.. in my output Srever Name's lenghth is upto 30 Char long.