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")

2/16/2020 11:40:24 AM


8 Answers

New Answer


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


Taste good clear explanation and good information 👌.I understood.Thank you 👍


Taste it had same result.But why fqdn() is different from fqdn(host)


Taste but why socket.getfqdn(host) returns ip address which I gave?


Taste why "google.com" is showing different output than "www.google.com" in ur code?


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


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


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