Solved

resolve hostnames to IPs

Posted on 2014-11-07
11
82 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
 

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
DevOps Toolchain Recommendations

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

 
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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell Mail is not working 5 90
Problem logging tar errors 11 54
unix example issues 18 73
how to split this type of line? 5 83
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now