Getting IP address

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Getting IP address

Post by manoj_hicool »

How can I print my system's local IP address in browser?

I tried the below methods and I did not get that.
print_r($_SERVER);
print "<br><br>";
print_r( $HTTP_SERVER_VARS);
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Getting IP address

Post by pbs »

User $_SERVER['SERVER_ADDR'];
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

I tried this and it is printing,

print "IP :: ".$_SERVER['SERVER_ADDR'];
IP :: 192.168.1.12

But my local IP address is in 192.168.8.102 .
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Getting IP address

Post by pbs »

Try $_SERVER['REMOTE_ADDR'];
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

I tried both the methods,
print "IP :: ".$_SERVER['SERVER_ADDR'];
print "IP1 :: ".$_SERVER['REMOTE_ADDR'];

It prints the result as,
IP :: 192.168.1.12
IP1 :: 192.168.1.10

It's not my system's local IP (192.168.8.102).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getting IP address

Post by VladSun »

$_SERVER['LOCAL_ADDR'] ?
There are 10 types of people in this world, those who understand binary and those who don't
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

It doesn't print anything to me.

$_SERVER['LOCAL_ADDR']
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getting IP address

Post by VladSun »

Is it Windows (version) or Linux?
There are 10 types of people in this world, those who understand binary and those who don't
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

It is linux system
Linux version 2.6.26-2-686 (Debian 2.6.26-17lenny2) (dannf@debian.org) (gcc version 4.1.3 20080704 (prerelease) (Debian 4.1.2-25)) #1 SMP Fri Aug 14 01:27:18 UTC 2009
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getting IP address

Post by VladSun »

What's the output of:

Code: Select all

ifconfig
?
There are 10 types of people in this world, those who understand binary and those who don't
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

/sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:1D:92:DE:49:9B
inet addr:192.168.8.20 Bcast:192.168.8.255 Mask:255.255.255.0
inet6 addr: fe80::21d:92ff:fede:499b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4281176819 errors:0 dropped:3002 overruns:0 frame:0
TX packets:295399131 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1770624014 (1.6 GiB) TX bytes:2600959972 (2.4 GiB)
Interrupt:23 Base address:0xdc00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:3520722 errors:0 dropped:0 overruns:0 frame:0
TX packets:3520722 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1208552913 (1.1 GiB) TX bytes:1208552913 (1.1 GiB)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getting IP address

Post by VladSun »

192.168.1.12/192.168.1.10 and 192.168.8.102 seem to be in different network segments.

Are you sure there isn't a router between your PC (192.168.1.10), which masks (DMZ, SNAT or port forwarding) the web server IP address (192.168.8.102) by replacing it with its own IP address - 192.168.1.12 ?

PS: :oops: Never mind, I think the $_SERVER['SERVER_ADDR'] has nothing to do with it ...
Strange...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getting IP address

Post by VladSun »

Code: Select all

echo gethostbyname($_SERVER['SERVER_NAME']);
?
There are 10 types of people in this world, those who understand binary and those who don't
manoj_hicool
Forum Newbie
Posts: 9
Joined: Mon Mar 08, 2010 1:22 am

Re: Getting IP address

Post by manoj_hicool »

It prints the IP as,
echo gethostbyname($_SERVER['SERVER_NAME']);

192.168.1.12
Post Reply