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

Discussion in 'Python' started by Hongyi Zhao, Jan 30, 2009.

  1. Hongyi Zhao

    Hongyi Zhao Guest

    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?
     
    Hongyi Zhao, Jan 30, 2009
    #1
    1. Advertising

  2. Hongyi Zhao

    Chris Rebert Guest

    Re: Want to write a script to do the batch conversion from domainname to IP.

    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
     
    Chris Rebert, Jan 30, 2009
    #2
    1. Advertising

  3. Hongyi Zhao

    Jeff McNeil Guest

    Re: Want to write a script to do the batch conversion from domainname to IP.

    On Jan 30, 7:33 am, Chris Rebert <> wrote:
    > 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


    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'
    >>>
     
    Jeff McNeil, Jan 30, 2009
    #3
  4. Hongyi Zhao

    Hongyi Zhao Guest

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

    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 :.
     
    Hongyi Zhao, Jan 30, 2009
    #4
  5. Hongyi Zhao

    Hongyi Zhao Guest

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

    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 :.
     
    Hongyi Zhao, Jan 30, 2009
    #5
  6. Re: Want to write a script to do the batch conversion from domainname to IP.

    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
     
    Gabriel Genellina, Jan 31, 2009
    #6
  7. Hongyi Zhao

    Hongyi Zhao Guest

    On Sat, 31 Jan 2009 04:10:39 -0200, "Gabriel Genellina"
    <> 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 :.
     
    Hongyi Zhao, Jan 31, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    716
    William Park
    Jan 30, 2006
  2. Chem Leakhina
    Replies:
    2
    Views:
    145
    Robert Klemme
    Jun 23, 2009
  3. Batch POD Conversion

    , Sep 9, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    168
  4. Hongyi Zhao
    Replies:
    20
    Views:
    1,037
    Hongyi Zhao
    Feb 1, 2009
  5. Dave Griffith

    Image::Magick->Write() doesn't want to write

    Dave Griffith, Nov 16, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    231
    Dave Griffith
    Nov 16, 2009
Loading...

Share This Page