Why socket.getfqdn() affects value of socket.getfqdn(host) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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")

16th Feb 2020, 11:40 AM
♪A ruba♪💖
♪A ruba♪💖 - avatar
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
16th Feb 2020, 12:57 PM
Taste
Taste - avatar
+ 10
Taste good clear explanation and good information 👌.I understood.Thank you 👍
16th Feb 2020, 3:04 PM
♪A ruba♪💖
♪A ruba♪💖 - avatar
+ 9
Taste it had same result.But why fqdn() is different from fqdn(host)
16th Feb 2020, 1:00 PM
♪A ruba♪💖
♪A ruba♪💖 - avatar
+ 9
Taste but why socket.getfqdn(host) returns ip address which I gave?
16th Feb 2020, 1:23 PM
♪A ruba♪💖
♪A ruba♪💖 - avatar
+ 9
Taste why "google.com" is showing different output than "www.google.com" in ur code?
16th Feb 2020, 2:16 PM
♪A ruba♪💖
♪A ruba♪💖 - avatar
+ 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
16th Feb 2020, 2:19 PM
Taste
Taste - avatar
+ 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
16th Feb 2020, 1:02 PM
Taste
Taste - avatar
+ 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
16th Feb 2020, 1:28 PM
Taste
Taste - avatar