Solved

resolve hostnames to IPs

Posted on 2014-11-07
11
91 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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