Forum Moderators: bakedjake

Message Too Old, No Replies

How to echo Ip when user is trying to login

         

DKDiveDude

5:55 pm on Dec 9, 2004 (gmt 0)

10+ Year Member



Ok, I have a Linux server, and I have edited the text file that displays when somebody tries to login to my server.

I also know that logfiles with the surfers IP address, and login attempt is recorded, and do read those logfiles.

However how can I actually echo that IP address, and perhaps even echo more information about the surfer attempting to access my server, at the time of access attempt. I mean echo it right back to the surfer?

AlexK

5:06 am on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It`s easy if you work with php...

function getUserIP() {// Obtain and encode users IP
// from phpBB2 (common.php + functions.php)
global $HTTP_SERVER_VARS, $HTTP_ENV_VARS, $REMOTE_ADDR;
if( getenv( 'HTTP_X_FORWARDED_FOR' )!= '' ) {
$client_ip = (!empty( $HTTP_SERVER_VARS[ 'REMOTE_ADDR' ]))
? $HTTP_SERVER_VARS[ 'REMOTE_ADDR' ]
: ((!empty( $HTTP_ENV_VARS[ 'REMOTE_ADDR' ]))
? $HTTP_ENV_VARS[ 'REMOTE_ADDR' ]
: $REMOTE_ADDR
);
$entries = explode( ',', getenv('HTTP_X_FORWARDED_FOR' ));
reset( $entries );
while( list(, $entry ) = each( $entries )) {
$entry = trim($entry);
if( preg_match( "/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry, $ip_list )) {
$private_ip = array( '/^0\./', '/^127\.0\.0\.1/',
'/^192\.168\..*/',
'/^172\.((1[6-9])¦(2[0-9])¦(3[0-1]))\..*/',
'/^10\..*/', '/^224\..*/',
'/^240\..*/'
);
$found_ip = preg_replace( $private_ip, $client_ip, $ip_list[ 1 ] );
if ( $client_ip!= $found_ip ) { $client_ip = $found_ip; break; }
}
}
} else {
$client_ip = (!empty( $HTTP_SERVER_VARS[ 'REMOTE_ADDR' ]))
? $HTTP_SERVER_VARS[ 'REMOTE_ADDR' ]
: ((!empty( $HTTP_ENV_VARS[ 'REMOTE_ADDR' ]))
? $HTTP_ENV_VARS[ 'REMOTE_ADDR' ]
: $REMOTE_ADDR
);
}// if( getenv( 'HTTP_X_FORWARDED_FOR')!= '' ) else
$ip_sep = explode( '.', $client_ip );
return sprintf( '%02x%02x%02x%02x', $ip_sep[ 0 ], $ip_sep[ 1 ], $ip_sep[ 2 ], $ip_sep[ 3 ]);
} // function getUserIP()

...and all nicely formatted, too!

DKDiveDude

5:30 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



Thanks Alex, but maybe I should have been more precise, because I actually already had a script that could echo the IP address.

My question is how do I integrate a such a function, into the login procedure?

Or in other words, how do I call such a procedure at the time a user is trying to log on to my server from the Internet?

Which file on my Linux server do I edit, and add a call to an IP echo function?

AlexK

11:53 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, you do need to be more precise!

...when somebody tries to login to my server

Login how? Via http, ftp, ssh, telnet...