473,671 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get the hostname

Hi
How can i get the hostname of my Linux PC?
I tried os.system('host name') but i cant save the hostname in a variable
like hostname = os.system('host name')

thanks
Lukas Schnieper
Jul 18 '05 #1
2 38984
admirm
2 New Member
Hi
How can i get the hostname of my Linux PC?
I tried os.system('host name') but i cant save the hostname in a variable
like hostname = os.system('host name')

thanks
Lukas Schnieper
Try this code:

import socket
host = socket.gethostn ame()
print host

Lp,
admirm
admir.mustafic@ xxxxxx.xx
Jul 27 '06 #2
admirm
2 New Member
Even better code :)
socket.gethostb yaddr(socket.ge thostname())
Jul 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2527
by: Claus van de Vlierd | last post by:
Hello , a) in the following script (under RedHat AS3 with PHP 4.3.2 ) I make a "DB::connect" to an existing "mysql" database named "docu_files_of_cvdv" . The strange thing is : it works -- even if I give as protocol the string "nonsenseprotocol" (instead of "unix" or "tcp") and as Hostname "nonsensehostname" ... !!
2
9821
by: Tim Veldhuizen | last post by:
Hi all! I'm attempting at writing a networked program. It is going to be a threaded irc server in c++ using almost nothing but oop code. And it needs to know the full hostname of the users that connect to it. I already get some info from this code: workersock = accept(mastersock, &sockaddr, &addrlen); printf("Received a Client Connection from: %s port: %d fd: %d\n", inet_ntoa(sockaddr.sin_addr), ntohs(sockaddr.sin_port), workersock);
2
5609
by: James M. | last post by:
I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup with NLB (single Affinity, also using SQLServer session state) that are hosting a few .NET ASP web applications under the Default Website in IIS, and accessing via a Intranet LAN (this is not publicly available). NETWEB1: NIC1 172.16.17.220 172.16.17.244 (NLB Virtual IP) NIC2 172.16.17.221
3
4790
by: Microlong® | last post by:
Currently, I want to get the IP address from giving hostname in the Active Server Page. I know the hostname, I want to get the IP address via hostname in an ASP page. -- Developer QA Dashboard Microsoft China Development Centre
3
3782
by: HiChetu | last post by:
I have a host which has two NIC cards; one configured for LAN connections, and another for external connections. Say the ip address are 1) x.x.x.x - for LAN 2) y.y.y.y - for external hostname = 'hichetu' With the following code snippet...
0
1516
by: James M via .NET 247 | last post by:
(I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup withNLB (single Affinity, also using SQLServer session state) thatare hosting a few .NET ASP web applications under the DefaultWebsite in IIS, and accessing via a Intranet LAN (this is notpublicly available). NETWEB1: NIC1 172.16.17.220 172.16.17.244 (NLB Virtual IP) NIC2 172.16.17.221 NETWEB2:
6
3591
by: Eric Rechter | last post by:
Hi, I only want to display the provider name from a hostname, so I need to divide the string to take only de characters from after the before last dot. For example: dsl-083-247-088-130.solcon.nl -I only wanna display "solcon.nl" adsl-dc-4d454.adsl.wanadoo.nl -I only wanna display "wanadoo.nl"
2
5327
by: slinkp | last post by:
Can anybody explain this one? pw@kermit ~ $ python Python 2.4.3 (#1, Jul 27 2006, 13:07:44) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib64/python2.4/UserDict.py", line 17, in __getitem__ def __getitem__(self, key): return self.data
3
7219
by: Mark Delaney | last post by:
When using the MS SQL 2005 JDBC driver, I now need to have the DNS name resolution to the client correctly set up. If not I get the following error: SQLState: 08S01 SQLError: 0 Message: hostname : hostname Where "hostname" is the client host name. It doesn't seem to matter if I
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.