Want to write a script to do the batch conversion from domain name to IP.

H

Hongyi Zhao

Hi all,

Suppose I've the entries like the following in my file:

------------------
116.52.155.237:80
ip-72-55-191-6.static.privatedns.com:3128
222.124.135.40:80
217.151.231.34:3128
202.106.121.134:80
211.161.197.182:80
hpc.be.itu.edu.tr:80
static3-117-183.worldinternetworkcorporation.com:80
------------------

Now, I want to convert the domain name to IP by using a python script,
e.g.,

ip-72-55-191-6.static.privatedns.com:3128

should be converted into the following form:

72.55.191.6:3128

any hints on this?
 
C

Chris Rebert

Hi all,

Suppose I've the entries like the following in my file:

------------------
116.52.155.237:80
ip-72-55-191-6.static.privatedns.com:3128
222.124.135.40:80
217.151.231.34:3128
202.106.121.134:80
211.161.197.182:80
hpc.be.itu.edu.tr:80
static3-117-183.worldinternetworkcorporation.com:80
------------------

Now, I want to convert the domain name to IP by using a python script,
e.g.,

ip-72-55-191-6.static.privatedns.com:3128

should be converted into the following form:

72.55.191.6:3128

any hints on this?

PyDNS might be a helpful library for writing such a script --
http://pydns.sourceforge.net/

Cheers,
Chris
 
J

Jeff McNeil

PyDNS might be a helpful library for writing such a script --http://pydns..sourceforge.net/

Cheers,
Chris

Why not just use socket.gethostbyname?

Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 
H

Hongyi Zhao

On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil
Why not just use socket.gethostbyname?

Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

See the following errors I in my case:

$ python
'import site' failed; use -v for traceback
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'socket' is not defined
 
H

Hongyi Zhao

On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil
Why not just use socket.gethostbyname?

Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import socket
socket.gethostbyname('ip-72-55-191-6.static.privatedns.com') '72.55.191.6'

See the following errors I in my case:

$ python
'import site' failed; use -v for traceback
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'socket' is not defined

Sorry for my carelessness. It's obviously due to the lack of the
socket module in my case.

Another issue is: how can I perform all of these steps in a python
script?
 
G

Gabriel Genellina

Those errors indicate that Python is not working correctly in your system.
You should fix it before going on.
Another issue is: how can I perform all of these steps in a python
script?

Start reading the tutorial and working the examples:
http://docs.python.org/tutorial/
In a short time (maybe shorter than you expect) you'll manage enough of
Python to do this.
Come back when you have specific questions, or try the tutor list:
http://mail.python.org/mailman/listinfo/tutor
 
H

Hongyi Zhao

Those errors indicate that Python is not working correctly in your system.
You should fix it before going on.

I use cygwin, I don't know whether the further discussion on fix this
issue is suitable for this group or not? If not, could you please
give me some hints on the newsgroups or maillists I should resort to?
Start reading the tutorial and working the examples:
http://docs.python.org/tutorial/
In a short time (maybe shorter than you expect) you'll manage enough of
Python to do this.
Come back when you have specific questions, or try the tutor list:
http://mail.python.org/mailman/listinfo/tutor

Thanks, I've subscribe to this list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top