How to get hostname from IP (Linux)?
In order to use nslookup
, host
or gethostbyname()
then the target's name will need to be registered with DNS or statically defined in the hosts file on the machine running your program. Yes, you could connect to the target with SSH or some other application and query it directly, but for a generic solution you'll need some sort of DNS entry for it.
Linux C API for getting remote server's hostname?
Although you can query DNS for hostnames, there's no standard protocol to ask a machine (an interface, really) what it calls itself (if it does even have a name for itself - that's not mandatory).
You'd need to implement and deploy a simple server program onto all the hosts you're interested in (it could be something as simple as adding a line to /etc/inetd.conf
to run /bin/hostname
if it's a Unix-like system), and a client library to access it.
How to get hostname and IP address of an arbitrary jenkins node in a pipeline job
def find_ip(node_name){
def node = Jenkins.instance.slaves.find{it.name.trim()==node_name.trim()}
if(node) {
def addr = InetAddress.getByName(node.computer.hostName)
def ip = addr.getHostAddress()
def host = addr.getHostName()
println "host=${host} ip=${ip}"
return host
}
}
Linux command to translate domain name to IP
Use this
$ dig +short stackoverflow.com
69.59.196.211
or this
$ host stackoverflow.com
stackoverflow.com has address 69.59.196.211
stackoverflow.com mail is handled by 30 alt2.aspmx.l.google.com.
stackoverflow.com mail is handled by 40 aspmx2.googlemail.com.
stackoverflow.com mail is handled by 50 aspmx3.googlemail.com.
stackoverflow.com mail is handled by 10 aspmx.l.google.com.
stackoverflow.com mail is handled by 20 alt1.aspmx.l.google.com.
Related Topics
I Get "Dquote>" as a Result of Executing a Program in Linux Shell
Shell Init Issue When Click Tab, What's Wrong with Getcwd
How to Speed Up Linux Kernel Compilation
Run a Shell Script in New Terminal from Current Terminal
What Happens After a Packet Is Captured
How to Get the Variable Value Inside the Eof Tags
How to Post Url in Data of a Curl Request
In Sshd Configuration What Does "Maxstartups 10:30:60" Mean
How and When to Use /Dev/Shm for Efficiency
How to Use "Py" Instead of "Python" at the Command Line in Linux
Learning Kernel Hacking and Embedded Development at Home
How to Know Which of the /Dev/Input/Eventx (X=0..7) Have the Linux Input Stream
How to Determine If Lcd Monitor Is Turned on from Linux Command Line