finding IP address of computer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    finding IP address of computer

    How do I find and print to screen the IP address of the computer my
    python program is working on?

  • Gregor Horvath

    #2
    Re: finding IP address of computer

    Chris schrieb:[color=blue]
    > How do I find and print to screen the IP address of the computer my
    > python program is working on?
    >[/color]

    IP adresses are bound to network interfaces not to computers.
    One Computer can have multiple network interfaces.

    --
    Servus, Gregor
    Firma Gregor Horvath, Ing. - Industrieberatung & Softwareentwicklung, Wien, infor:COM, Tryton, ERP, Web, GNU/Linux

    Comment

    • BartlebyScrivener

      #3
      Re: finding IP address of computer

      One way:
      [color=blue][color=green][color=darkred]
      >>> import socket
      >>> socket.getaddri nfo(socket.geth ostname(), None)[0][4][0][/color][/color][/color]

      It was the first google hit

      Comment

      • Chris

        #4
        Re: finding IP address of computer

        hehe, works a charm, cheers mate.

        Comment

        • Jorge Godoy

          #5
          Re: finding IP address of computer

          Chris wrote:
          [color=blue]
          > hehe, works a charm, cheers mate.[/color]

          Beware that if you have a different entry in your hosts file you can match a
          different name.

          Test it:

          - add "127.0.0.2 yourhost.yourdo main yourhost" to /etc/hosts
          - rerun the code.

          You'll see "127.0.0.2" as the result. So take that into account.

          --
          Jorge Godoy <godoy@ieee.org >

          "Quidquid latine dictum sit, altum sonatur."
          - Qualquer coisa dita em latim soa profundo.
          - Anything said in Latin sounds smart.

          Comment

          • sturlamolden

            #6
            Re: finding IP address of computer

            print '127.0.0.1'

            :-P

            Comment

            • Grant Edwards

              #7
              Re: finding IP address of computer

              On 2006-04-27, Gregor Horvath <g.horvath@gmx. at> wrote:[color=blue]
              > Chris schrieb:[color=green]
              >> How do I find and print to screen the IP address of the computer my
              >> python program is working on?
              >>[/color]
              >
              > IP adresses are bound to network interfaces not to computers.
              > One Computer can have multiple network interfaces.[/color]

              And each interface can have any number if IP addresses
              (including none).

              --
              Grant Edwards grante Yow! I feel like a wet
              at parking meter on Darvon!
              visi.com

              Comment

              • Terry Reedy

                #8
                Re: finding IP address of computer


                "Grant Edwards" <grante@visi.co m> wrote in message
                news:12525ctc1a ne5e5@corp.supe rnews.com...[color=blue]
                > On 2006-04-27, Gregor Horvath <g.horvath@gmx. at> wrote:[color=green]
                >> Chris schrieb:[color=darkred]
                >>> How do I find and print to screen the IP address of the computer my
                >>> python program is working on?
                >>>[/color]
                >>
                >> IP adresses are bound to network interfaces not to computers.
                >> One Computer can have multiple network interfaces.[/color]
                >
                > And each interface can have any number if IP addresses
                > (including none).[/color]

                To answer the OP for typical situations: if you are accessing the internet
                via a local network, the network administrator should be able to tell you.
                In fact, for some networks, the IP address is part of the interface setup.
                If the network is run by a router, it should be able to tell you. If you
                are sitting behind a NAT (network address translation) router and you want
                to know the external address, there are web pages that echo your externally
                visible address back to you.

                Terry Jan Reedy



                Comment

                • DarkBlue

                  #9
                  Re: finding IP address of computer

                  Chris wrote:
                  [color=blue]
                  > How do I find and print to screen the IP address of the computer my
                  > python program is working on?[/color]

                  def readip():
                  import re, urllib
                  f = urllib.urlopen( 'http://checkip.dyndns. org')
                  s = f.read()
                  m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
                  return m.group(0)

                  myip = readip()

                  Comment

                  • Paul Watson

                    #10
                    Re: finding IP address of computer

                    DarkBlue wrote:[color=blue]
                    > Chris wrote:
                    >
                    >[color=green]
                    >>How do I find and print to screen the IP address of the computer my
                    >>python program is working on?[/color]
                    >
                    >
                    > def readip():
                    > import re, urllib
                    > f = urllib.urlopen( 'http://checkip.dyndns. org')
                    > s = f.read()
                    > m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
                    > return m.group(0)
                    >
                    > myip = readip()[/color]

                    IP address and other browser header information available at:

                    Use this page to check the HTTP headers transmitted by your browser

                    Comment

                    Working...