Cross-platform way to retrieve the current (Operative system) DNSserver IP address in python

Discussion in 'Python' started by joamag, Apr 22, 2010.

  1. joamag

    joamag Guest

    Does anybody know a cross platform way to retrieve the default DNS
    server IP address in python ?

    Thanks !
    João
     
    joamag, Apr 22, 2010
    #1
    1. Advertising

  2. joamag

    DarkBlue Guest

    On Apr 22, 4:55 pm, joamag <> wrote:
    > Does anybody know a cross platform way to retrieve the default DNS
    > server IP address in python ?
    >
    > Thanks !
    > João



    import os,urllib2,re


    def getIpAddr():
    """
    Function for parsing external ip adress by pinging dyndns.com
    """
    External_IP=urllib2.urlopen('http://checkip.dyndns.com/').read()
    m = re.search(r"(([0-9]+\.){3}[0-9]+)", External_IP)
    my_IP= m.group(1)
    return my_IP




    print('Current Ip from DynDns : %s ') % getIpAddr()



    this gets you your ip address

    hope it helps.
     
    DarkBlue, Apr 24, 2010
    #2
    1. Advertising

  3. joamag

    joamag Guest

    On 24 Abr, 14:50, DarkBlue <> wrote:
    > On Apr 22, 4:55 pm, joamag <> wrote:
    >
    > > Does anybody know a cross platform way to retrieve the default DNS
    > > server IP address in python ?

    >
    > > Thanks !
    > > João

    >
    > import os,urllib2,re
    >
    > def getIpAddr():
    >     """
    >     Function for parsing external ip adress by pinging dyndns.com
    >     """
    >     External_IP=urllib2.urlopen('http://checkip.dyndns.com/').read()
    >     m = re.search(r"(([0-9]+\.){3}[0-9]+)", External_IP)
    >     my_IP= m.group(1)
    >     return my_IP
    >
    > print('Current Ip from DynDns :  %s ') % getIpAddr()
    >
    > this gets you your ip address
    >
    > hope it helps.


    Hi,

    It's not my ip address that I want to discover... I want to discover
    my default dns server ip address.
    This ip is stored in an operative system basis.

    Dos anyone know how to get it ?
     
    joamag, Apr 27, 2010
    #3
  4. joamag

    Hans Mulder Guest

    Re: Cross-platform way to retrieve the current (Operative system)DNS server IP address in python

    joamag wrote:

    > It's not my ip address that I want to discover... I want to discover
    > my default dns server ip address.
    > This ip is stored in an operative system basis.
    >
    > Dos anyone know how to get it ?


    You asked for a cross-platform solution; there probably isn't one.

    The code below works on Unix and MacOS X.
    If you can find code that works on Windows, you can cobble together
    somthing that will work on most platforms.

    dns_ips = []

    for line in file('/etc/resolv.conf', 'r'):
    columns = line.split()
    if columns[0] == 'nameserver':
    dns_ips.extend(columns[1:])

    print dns_ips


    Hope this help,

    -- HansM
     
    Hans Mulder, Apr 30, 2010
    #4
    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. Alex Martelli
    Replies:
    25
    Views:
    1,465
    MrJean1
    Dec 1, 2005
  2. howa
    Replies:
    5
    Views:
    350
    James Kanze
    Jan 20, 2008
  3. Future_News

    Is this a binary operative?

    Future_News, Oct 21, 2009, in forum: C Programming
    Replies:
    0
    Views:
    342
    Future_News
    Oct 21, 2009
  4. Peter Flynn

    psgml NOFILL not operative

    Peter Flynn, Nov 15, 2009, in forum: XML
    Replies:
    0
    Views:
    936
    Peter Flynn
    Nov 15, 2009
  5. Peter Flynn

    psgml NOFILL not operative

    Peter Flynn, Nov 21, 2009, in forum: XML
    Replies:
    3
    Views:
    1,008
    Joe Kesselman
    Nov 23, 2009
Loading...

Share This Page