Skip to main content
b0rked copypaste
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

I think it just returns whatever the underlying gethostname() call does. For example (though this is on Linux):

# hostname foobar
# python -c 'import socket; print(socket.gethostname()) '
foobar
# hostname foobar.example.org                                                                                        
# python -c 'import socket; print(socket.gethostname()) '
foobar.example.org

If you just want the hostname part, it's not hard to remove the rest:

# python -c 'import socket; import re; print(re.sub("\..*", "", socket.gethostname()))'
foobar

I think it just returns whatever the underlying gethostname() call does. For example (though this is on Linux):

# hostname foobar
# python -c 'import socket; print(socket.gethostname()) '
foobar
# hostname foobar.example.org                                                                                       # python -c 'import socket; print(socket.gethostname()) '
foobar.example.org

If you just want the hostname part, it's not hard to remove the rest:

# python -c 'import socket; import re; print(re.sub("\..*", "", socket.gethostname()))'
foobar

I think it just returns whatever the underlying gethostname() call does. For example (though this is on Linux):

# hostname foobar
# python -c 'import socket; print(socket.gethostname())'
foobar
# hostname foobar.example.org 
# python -c 'import socket; print(socket.gethostname())'
foobar.example.org

If you just want the hostname part, it's not hard to remove the rest:

# python -c 'import socket; import re; print(re.sub("\..*", "", socket.gethostname()))'
foobar
Source Link
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

I think it just returns whatever the underlying gethostname() call does. For example (though this is on Linux):

# hostname foobar
# python -c 'import socket; print(socket.gethostname()) '
foobar
# hostname foobar.example.org                                                                                       # python -c 'import socket; print(socket.gethostname()) '
foobar.example.org

If you just want the hostname part, it's not hard to remove the rest:

# python -c 'import socket; import re; print(re.sub("\..*", "", socket.gethostname()))'
foobar