Php get local IP address php get remote IP address
Php command to obtain the local IP address php command to obtain the remote IP address complete code:
- //
- Echo $ _ SERVER ['remote _ ADDR '];
-
- // Local IP address
- Function get_local_ip (){
- $ Preg = "/\ A ([0-9]? [0-9]) | (1 [0-9] {2}) | (2 [0-4] [0-9]) | (25 [0-5]) \.) {3} ([0-9]? [0-9]) | (1 [0-9] {2}) | (2 [0-4] [0-9]) | (25 [0-5]) \ Z /";
- // Obtain the real IP address of the local machine whose operating system is win2000/xp or win7
- Exec ("ipconfig", $ out, $ stats );
- If (! Emptyempty ($ out )){
- Foreach ($ out AS $ row ){
- If (strstr ($ row, "IP") & strstr ($ row ,":")&&! Strstr ($ row, "IPv6 ")){
- $ TmpIp = explode (":", $ row );
- If (preg_match ($ preg, trim ($ tmpIp [1]) {
- Return trim ($ tmpIp [1]);
- }
- }
- }
- }
- // Obtain the real IP address of the local machine whose operating system is linux
- Exec ("ifconfig", $ out, $ stats );
- If (! Emptyempty ($ out )){
- If (isset ($ out [1]) & strstr ($ out [1], 'addr :')){
- $ TmpArray = explode (":", $ out [1]);
- $ TmpIp = explode ("", $ tmpArray [1]);
- If (preg_match ($ preg, trim ($ tmpIp [0]) {
- Return trim ($ tmpIp [0]);
- }
- }
- }
- Return '2014. 0.0.1 ';
- }
|