+ 18
Why socket.getfqdn() affects value of socket.getfqdn(host)
import socket host=input() try: s=socket.gethostname() p=socket.getfqdn() addr=socket.getfqdn(host) print("domain name is"+" "+addr) print(p) print(addr) except socket.gaierror: print("The ip doesn't exist") #Why this output is different from above output import socket host=input() try: addr=socket.gethostname() p=socket.fqdn(host) print("IP Address is"+" "+addr) print(p) except socket.gaierror: print("The ip doesn't exist")
8 Answers
+ 6
its not. the first code print addr from socket.getfqdn.
but the second addr never touch getfqdn at all.
compare the addr from first example with p from second example. it should have a same result
https://code.sololearn.com/cjViwdnv912g/?ref=app
+ 10
Taste good clear explanation and good information đ.I understood.Thank you đ
+ 9
Taste it had same result.But why fqdn() is different from fqdn(host)
+ 9
Taste but why socket.getfqdn(host) returns ip address which I gave?
+ 9
Taste why "google.com" is showing different output than "www.google.com" in ur code?
+ 3
its their decision back in a day to unify the hostname of their services under 1e100.net
here: https://support.google.com/faqs/answer/174717?hl=en
+ 2
its in the docs, if the parameter is empty getfqn will interpreted as local host
https://docs.python.org/3/library/socket.html#socket.getfqdn
+ 2
its not exactly an ip address, but thats what the function used for.
you give the host name it'll find the fqdn.
you give nothing it'll get it from local host