Solved

resolve hostnames to IPs

Posted on 2014-11-07
11
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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