简体   繁体   English

在 shell 脚本 linux 中使用 IP 地址查找主机名

[英]finding hostname using IP address in shell script linux

I'd appreciate it if anyone could help me with this issue, I need a shell script that is capable of finding IP addresses using the hostname.如果有人可以帮助我解决这个问题,我将不胜感激,我需要一个能够使用主机名查找 IP 地址的 shell 脚本。 can anyone help me?谁能帮我?

To find an IP address from a URL, you can use nslookup .要从 URL 中查找 IP 地址,可以使用nslookup If you want only the IP address itself, you can pipe it to grep and use a lookbehind regex to filter for the part after the text "Address: ".如果您只想要 IP 地址本身,您可以将 pipe 到grep并使用后向正则表达式过滤文本“地址:”之后的部分

nslookup google.com | grep -Po "(?<=^Address: ).*"

What have you tried out so far?到目前为止你尝试过什么? Though for starters there are a couple of tools you can use to achieve this.虽然对于初学者来说,有几个工具可以用来实现这一点。 If using linux, nmblookup -A <hostname.com> would produce something like this Looking up status of <IP address> Let me know exactly what you want to achieve.如果使用 linux, Looking up status of <IP address> nmblookup -A <hostname.com>会产生类似这样的结果。

okello@okello-XPS-13-7390:~$ nmblookup -A google.com
Looking up status of 172.217.170.206

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

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