简体   繁体   中英

How to find the IP address of hostname in VPN - AngularJS

I'm developing a website for our company, and I'm looking for a way to convert hostname with FQDN, to an IP address using AngularJS. Please note that we are using VPN and therefore I cannot do the conversion using external websites.

Usually, I'm getting this info by using shell command "host machineName.dnsdomain". But now I can't find a way to achieve the same results.

So as mentioned, I have an hostname for example : infraMachine.rus.company.com

And I need a way to find the IP address of this host.

Fairly certain this cannot be done. From Javascript, you can only get the HTTP header, which may or may not have an IP address (typically only has the host name). Part of the browser's program is to abstract the TCP/IP address away and only allow you to deal with a host name.

However you could use your preferred server-side language to print the server's IP to the client, and then use it however you like. For example, in PHP:

<script type="text/javascript">
    var ip = "<?php echo gethostbyname('example.com'); ?>";
    alert(ip);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM