Find an IP access from AWS (PHP)

Find an IP access from AWS (PHP)

When you use the Amazon server, if you get a server IP, the private IP is output.

So I made it to save the official IP.

<?
if(in_array(substr($_SERVER['SERVER_ADDR'], 0, 3), array('172')))
	if(strrpos(gethostname(), '.compute.internal')!==false)
		$_SERVER['SERVER_ADDR'] = file_get_contents('http://169.254.169.254/latest/meta-data/public-ipv4');

echo $_SERVER['SERVER_ADDR'];
?>

Leave a Reply

이메일 주소는 공개되지 않습니다. (* 질문, 건의사항 등은 "질문게시판"을 이용해주세요)