Solved

resolve hostnames to IPs

Posted on 2014-11-07
11
84 Views
Last Modified: 2015-01-13
I would like to resolve a list of hostnames to IP addresses. How do I accomplish that?
0
Comment
Question by:totoroha
  • 4
  • 4
  • 2
  • +1
11 Comments
 

Author Comment

by:totoroha
ID: 40429708
I would like to resolve a list of hostnames to IP addresses. How do I accomplish that?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429711
In bash or python (you posted in both zones)
0
 
LVL 13

Accepted Solution

by:
Rizzle earned 250 total points
ID: 40429712
You can use something callef FastResolver.

http://www.nirsoft.net/utils/fastresolver.html
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:totoroha
ID: 40429724
I know about that tool, but I want to import a lists of websites, domain names and export it to a txt file with the ip address.
I don't mind if you can help me with both bash and python.

Thank you so much.
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 40429738
Here is a good example:
import socket
hostname = 'maps.google.com'
addr = socket.gethostbyname(hostname)
print 'The address of ', hostname, 'is', addr 

Open in new window


http://codedrop.blogspot.com/2011/02/turning-hostname-into-ip-address.html
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429739
BASH is probably easiest to get the information, and then you can wrap a python loop around it rather easily, and use Python to write it to a file.

So, we need to be able to execute a python script that will run this bash command to get the IPs.

The first thing we're going to use is a group of tools piped together:

dig
grep
awk

Dig gets the records.
Grep filters the results to give us only lines with IPs
awk returns only the column that contains IPs:

Here's your command:
dig google.com | grep -P '([0-9]{1,}\.){3}' | awk '{print $5}'

Open in new window


Now, the first thing you'l notice here is that we are getting a list of A records for the domain. What do you want to do with the rollovers?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429740
@becraig: does that get all hostname IPs?
0
 

Author Comment

by:totoroha
ID: 40429776
I think with becraig code, we have to put in the host name one by one. But if I put a variable there, replace it with the value from the imported text file, we can have the list of ip addresses. Is that correct Michael?
0
 

Author Comment

by:totoroha
ID: 40436220
can anyone help me with this?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40439020
Sorry... been taken away by personal matters.

His chide dies not require you enter Simon's one at a time. Like what I have you, it requires you build a loop with values (list of domain names) out pull then from other source like a database.

What level of programming expertise do you have? Are you comfortable building loops?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40468876
Hi totoroha you can simply loop this through the hostnames from an input.

Some reading material
http://www.java2s.com/Code/Python/File/Loopthroughafile.htm
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question