Find localhost’s IP number

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

    Find localhost’s IP number

    Hi, I am running apache on local pc/ under Windows.

    I need to figure out the ip number of the pc inside PHP. This is the
    number available when you do ipconfig, and not the 127.0.0.1!

    So the slow way I have figured out is to do a system call to doc,
    using `ipconfig`, and then regex the result and figure out the ip.
    Is there a fater/more efficient way to do this?

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438714
  • Gordon Burditt

    #2
    Re: Find localhost’s IP number

    >Hi, I am running apache on local pc/ under Windows.[color=blue]
    >
    >I need to figure out the ip number of the pc inside PHP. This is the
    >number available when you do ipconfig, and not the 127.0.0.1![/color]

    Never assume that a web server has only one IP address. It isn't
    that uncommon for a web server to occupy an entire class C. (253
    usable addresses or so.)
    [color=blue]
    >So the slow way I have figured out is to do a system call to doc,
    >using `ipconfig`, and then regex the result and figure out the ip.
    >Is there a fater/more efficient way to do this?[/color]

    If you want the IP address that the client contacted the server on,
    look at $_SERVER['SERVER_ADDR']. This may well vary if the server
    has IP-based virtual hosts, and it might end up being 127.0.0.1 if
    you accessed it with http://127.0.0.1/foo.php from your browser on
    the server itself.

    Gordon L. Burditt

    Comment

    • Chung Leong

      #3
      Re: Find localhost?s IP number


      "steve" <UseLinkToEmail @dbForumz.com> wrote in message
      news:TvgLc.5519 3$5Y.34823@cycl ops.nntpserver. com...[color=blue]
      > Hi, I am running apache on local pc/ under Windows.
      >
      > I need to figure out the ip number of the pc inside PHP. This is the
      > number available when you do ipconfig, and not the 127.0.0.1!
      >
      > So the slow way I have figured out is to do a system call to doc,
      > using `ipconfig`, and then regex the result and figure out the ip.
      > Is there a fater/more efficient way to do this?
      >
      > --
      > http://www.dbForumz.com/ This article was posted by author's request
      > Articles individually checked for conformance to usenet standards
      > Topic URL:[/color]
      http://www.dbForumz.com/PHP-Find-loc...ict131475.html[color=blue]
      > Visit Topic URL to contact author (reg. req'd). Report abuse:[/color]


      gethostbynamel( $dns_name_of_co mputer).


      Comment

      • steve

        #4
        Re: Re: Find localhost?s IP number

        "Chung Leong" wrote:[color=blue]
        > "steve" <UseLinkToEmail @dbForumz.com> wrote in message
        > news:TvgLc.5519 3Y.34823@cyclop s.nntpserver.co m...[color=green]
        > > Hi, I am running apache on local pc/ under Windows.
        > >
        > > I need to figure out the ip number of the pc inside PHP. This is[/color]
        > the[color=green]
        > > number available when you do ipconfig, and not the 127.0.0.1!
        > >
        > > So the slow way I have figured out is to do a system call to doc,
        > > using `ipconfig`, and then regex the result and figure out the[/color]
        > ip.[color=green]
        > > Is there a fater/more efficient way to do this?
        > >
        > > --
        > > http://www.dbForumz.com/ This article was posted by[/color]
        > author’s request[color=green]
        > > Articles individually checked for conformance to usenet standards
        > > Topic URL:[/color]
        > http://www.dbForumz.com/PHP-Find-loc...ict131475.html[color=green]
        > > Visit Topic URL to contact author (reg. req’d). Report[/color]
        > abuse:
        > http://www.dbForumz.com/eform.php?p=438714
        >
        > gethostbynamel( $dns_name_of_co mputer).[/color]

        I don’t have DNS on my pc, so I tried
        gethostbynamel( ’localhost’)
        but it returns 127.0.0.1

        --
        http://www.dbForumz.com/ This article was posted by author's request
        Articles individually checked for conformance to usenet standards
        Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
        Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438855

        Comment

        • steve

          #5
          Re: Re: Find localhost?s IP number

          "steve" wrote:[color=blue]
          > [quote:5b9ab702e 4="Chung Leong"]"steve"
          > <UseLinkToEmail @dbForumz.com> wrote in message
          > news:TvgLc.5519 3Y.34823@cyclop s.nntpserver.co m...[color=green]
          > > Hi, I am running apache on local pc/ under Windows.
          > >
          > > I need to figure out the ip number of the pc inside PHP. This is[/color]
          > the[color=green]
          > > number available when you do ipconfig, and not the 127.0.0.1!
          > >
          > > So the slow way I have figured out is to do a system call to doc,
          > > using `ipconfig`, and then regex the result and figure out the[/color]
          > ip.[color=green]
          > > Is there a fater/more efficient way to do this?
          > >
          > > --
          > > http://www.dbForumz.com/ This article was posted by[/color]
          > author’s request[color=green]
          > > Articles individually checked for conformance to usenet standards
          > > Topic URL:[/color]
          > http://www.dbForumz.com/PHP-Find-loc...ict131475.html[color=green]
          > > Visit Topic URL to contact author (reg. req’d). Report[/color]
          > abuse:
          > http://www.dbForumz.com/eform.php?p=438714
          >
          > gethostbynamel( $dns_name_of_co mputer).[/color]

          I don’t have DNS on my pc, so I tried
          gethostbynamel( ’localhost’)
          but it returns 127.0.0.1[/quote:5b9ab702e 4]

          It works! must do it this way:
          $hosts=gethostb ynamel(’’); (see
          http://ca2.php.net/manual/en/functio...ostbynamel.php)

          --
          http://www.dbForumz.com/ This article was posted by author's request
          Articles individually checked for conformance to usenet standards
          Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
          Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438856

          Comment

          • steve

            #6
            Re: Re: Find localhost?s IP number

            "steve" wrote:[color=blue]
            > [quote:a57631114 3="steve"][quote:a57631114 3="Chung[/color]
            Leong"]"steve"[color=blue]
            > <UseLinkToEmail @dbForumz.com> wrote in message
            > news:TvgLc.5519 3Y.34823@cyclop s.nntpserver.co m...[color=green]
            > > Hi, I am running apache on local pc/ under Windows.
            > >
            > > I need to figure out the ip number of the pc inside PHP. This is[/color]
            > the[color=green]
            > > number available when you do ipconfig, and not the 127.0.0.1!
            > >
            > > So the slow way I have figured out is to do a system call to doc,
            > > using `ipconfig`, and then regex the result and figure out the[/color]
            > ip.[color=green]
            > > Is there a fater/more efficient way to do this?
            > >
            > > --
            > > http://www.dbForumz.com/ This article was posted by[/color]
            > author’s request[color=green]
            > > Articles individually checked for conformance to usenet standards
            > > Topic URL:[/color]
            > http://www.dbForumz.com/PHP-Find-loc...ict131475.html[color=green]
            > > Visit Topic URL to contact author (reg. req’d). Report[/color]
            > abuse:
            > http://www.dbForumz.com/eform.php?p=438714
            >
            > gethostbynamel( $dns_name_of_co mputer).[/color]

            I don’t have DNS on my pc, so I tried
            gethostbynamel( ’localhost’)
            but it returns 127.0.0.1[/quote:a57631114 3]

            It works! must do it this way:
            $hosts=gethostb ynamel(’’); (see
            http://ca2.php.net/manual/en/functio...stbynamel.php)[/quote:a57631114 3]

            And a quick note, the $hosts variable above is an array. Take
            $hosts[0] as the IP number!

            Comment

            • George Kinney

              #7
              Re: Re: Find localhost?s IP number


              "steve" <UseLinkToEmail @dbForumz.com> wrote in message
              news:wkiLc.5644 1$5Y.4868@cyclo ps.nntpserver.c om...[color=blue][color=green]
              > > gethostbynamel( $dns_name_of_co mputer).[/color]
              >
              > I don't have DNS on my pc, so I tried
              > gethostbynamel( 'localhost')
              > but it returns 127.0.0.1[/quote:a57631114 3]
              >
              > It works! must do it this way:
              > $hosts=gethostb ynamel(''); (see
              >[/color]
              http://ca2.php.net/manual/en/functio...stbynamel.php)[/quote:a57631114 3][color=blue]
              >
              > And a quick note, the $hosts variable above is an array. Take
              > $hosts[0] as the IP number![/color]

              Just to clarify: getbyhostname(' localhost') *should* return 127.0.0.1, since
              it almost always
              defined as such in your hosts file. You should actually either use '', like
              you did, or your known
              machine name 'someserver.som edomain.com' if you want its actual IP.

              And you don't need to have DNS on your PC, if you can look up *any* hostname
              (not already
              defined in your hosts file) then you are accessing a DNS server somewhere.
              (look up anything
              via nslookup at a command line, and it will tell you what server you are
              currently using as part of
              its response.)


              Comment

              Working...