Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Want to write a script to do the batch conversion from domain name to IP.

Reply
Thread Tools

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

 
 
Hongyi Zhao
Guest
Posts: n/a
 
      01-30-2009
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?
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      01-30-2009
On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao <> wrote:
> 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

--
Follow the path of the Iguana...
http://rebertia.com
 
Reply With Quote
 
 
 
 
Jeff McNeil
Guest
Posts: n/a
 
      01-30-2009
On Jan 30, 7:33*am, Chris Rebert <c...@rebertia.com> wrote:
> On Fri, Jan 30, 2009 at 4:27 AM, Hongyi Zhao <hongyi.z...@gmail.com> wrote:
> > 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
>
> --
> Follow the path of the Iguana...http://rebertia.com


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'
>>>




 
Reply With Quote
 
Hongyi Zhao
Guest
Posts: n/a
 
      01-30-2009
On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil
<> wrote:
[snipped]
>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.
>>> import socket

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named socket
>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'socket' is not defined

--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
 
Reply With Quote
 
Hongyi Zhao
Guest
Posts: n/a
 
      01-30-2009
On Fri, 30 Jan 2009 22:48:00 +0800, Hongyi Zhao
<> wrote:

>On Fri, 30 Jan 2009 05:41:29 -0800 (PST), Jeff McNeil
><> wrote:
>[snipped]
>>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.
>>>> import socket

>Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
>ImportError: No module named socket
>>>> socket.gethostbyname('ip-72-55-191-6.static.privatedns.com')

>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?

--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-31-2009
En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao <>
escribió:

>> See the following errors I in my case:
>>
>> $ python
>> 'import site' failed; use -v for traceback


>>>>> import socket

>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> ImportError: No module named socket


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

--
Gabriel Genellina

 
Reply With Quote
 
Hongyi Zhao
Guest
Posts: n/a
 
      01-31-2009
On Sat, 31 Jan 2009 04:10:39 -0200, "Gabriel Genellina"
<gagsl-> wrote:

>En Fri, 30 Jan 2009 12:53:33 -0200, Hongyi Zhao <>
>escribi$)A(.:
>
>>> See the following errors I in my case:
>>>
>>> $ python
>>> 'import site' failed; use -v for traceback

>
>>>>>> import socket
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> ImportError: No module named socket

>
>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?

>
>> 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


Thanks, I've subscribe to this list.

--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to write a script to do the batch conversion from domain name to IP. Hongyi Zhao Perl Misc 20 02-01-2009 05:24 AM
batch tiff to jpeg conversion script rtilley@vt.edu Python 11 01-30-2006 03:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57