-1

I am using software called gns3 to build networks.

I have the need to find out devices external ip from within an gns3 internal network. This would be like a pc behind a router doing NAT.

Please could someone tell me if there is a way that you can echo out the clients external ip in php so I can add a web server to one of my virtual networks within gns3 so I can visit it on some devices and find their external ip’s for testing?

Thanks in advance

1 Answers1

0

You need to make a request to an external website that could tell you the ip address you have. You may use checkip.dyndns.org - click the link to see your own ip addres.

if you want to do that from php here is an example code:

<?php

//get website content as a string
$ipCheckUrl = 'http://checkip.dyndns.org';
$subject = file_get_contents($ipCheckUrl);

//extract from string just ip address
$pattern = '/Current IP Address\:\s*(\d+\.\d+\.\d+\.\d+)/U';
$ip = preg_match($pattern,$subject,$result) ? $result[1] : 'Error';

//print ip address.
echo $ip;
Jimmix
  • 5,644
  • 6
  • 44
  • 71
  • Hi, this would work but my labs don’t have access to the internet. And even if they did I would just get the external ip of my physical router – AvidPontoon Jun 01 '19 at 09:25
  • @AvidPontoon if you are able to put a php server PHP+Apache inside your network then put there a php script that reads IP address of the visitor and returns that IP address (like checkip.dyndns.org) as text so the visitor (client) can read it. Examples of server scripts are [here](https://stackoverflow.com/questions/13646690/how-to-get-real-ip-from-visitor) and on client you just put `$ip = file_get_contents('ip-or-url-of-the-server')` – Jimmix Jun 01 '19 at 13:48