简体   繁体   English

如何在VPN中查找主机名的IP地址-AngularJS

[英]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. 我正在为我们公司开发一个网站,并且正在寻找一种使用AngularJS将带有FQDN的主机名转换为IP地址的方法。 Please note that we are using VPN and therefore I cannot do the conversion using external websites. 请注意,我们正在使用VPN,因此我无法使用外部网站进行转换。

Usually, I'm getting this info by using shell command "host machineName.dnsdomain". 通常,我通过使用shell命令“ 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 因此,如上所述,我有一个主机名:infraMachine.rus.company.com

And I need a way to find the IP address of this host. 而且我需要找到该主机IP地址的方法。

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). 从Javascript,您只能获取HTTP标头,该标头可能有也可能没有IP地址(通常只有主机名)。 Part of the browser's program is to abstract the TCP/IP address away and only allow you to deal with a host name. 浏览器程序的一部分是抽象出TCP / IP地址,只允许您处理主机名。

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. 但是,您可以使用首选的服务器端语言将服务器的IP打印到客户端,然后根据需要使用它。 For example, in PHP: 例如,在PHP中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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