0

hi

Ive been posed this problem. A friend does maintenance on a companies network, and would like to do it remotely. Currently, their IP changes every 24hrs and so he has to phone them to find their IP so that he can log in...

He asked me to write him something which would pull the host's IP and email it to him, probably running as a cron job...

I can retrieve a visitors IP using PHP, but have no idea how to get the hosts IP...?

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by monica singh
0

hi

Ive been posed this problem. A friend does maintenance on a companies network, and would like to do it remotely. Currently, their IP changes every 24hrs and so he has to phone them to find their IP so that he can log in...

He asked me to write him something which would pull the host's IP and email it to him, probably running as a cron job...

I can retrieve a visitors IP using PHP, but have no idea how to get the hosts IP...?

I dont have any experience working with cron jobs but to retrieve the host's ip address u can use--

$_SERVER['SERVER_ADDR']

.
Send its value through cron job and ur problem is solved...
cheers!

0

Hi,

gethostbyname() example

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

gethostbyaddr() example

<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;
?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.