Get the private ip address at a specific ethernet port in PHP -


i have php coe running on server. want ip address of local system. question has been asked before - php how local ip of system

when use of solutions mentioned in above post, can hostname, not ip address.

e.g. on machine have

eth0:10.0.2.15
eth1:192.168.1.115

when run following code:

$localip = gethostbyname(gethostname()); 

i hostname - localvm. want 192.168.1.115

can private ip address? more can ip address @ specific port?

you ip address of specific network port in linux like:

function getinterfaceip($interface = 'eth0') {         $interfacecommand = "/sbin/ifconfig " . $interface . " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'";         $output = exec($interfacecommand);          return $output; }  echo getinterfaceip('eth0'); 

note command syntax may differ os os. example works linux. php doesn't have built-in classes this.

you may want add command - getting list of network interfaces available ('ifconfig -s' provides those).


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -