Hostname: Difference between revisions
Content added Content deleted
m (→[[Java]]: Use Java header instead) |
m (Switch to header template) |
||
Line 3: | Line 3: | ||
Find the name of the host on which the routine is running. |
Find the name of the host on which the routine is running. |
||
== |
=={{header|C}}== |
||
[[Category:C]] |
|||
'''Compiler:''' [[GCC]] 4.0.1 |
'''Compiler:''' [[GCC]] 4.0.1 |
||
Line 18: | Line 17: | ||
} |
} |
||
== |
=={{header|C sharp|C#}}== |
||
[[Category:C_sharp]] |
|||
System.Net.Dns.GetHostName(); |
System.Net.Dns.GetHostName(); |
||
== |
=={{header|IDL}}== |
||
[[Category:IDL]] |
|||
hostname = GETENV('computername') |
hostname = GETENV('computername') |
||
Line 31: | Line 27: | ||
String hostname = java.net.InetAddress.getLocalHost().getHostName(); |
String hostname = java.net.InetAddress.getLocalHost().getHostName(); |
||
== |
=={{header|Perl}}== |
||
[[Category:Perl]] |
|||
'''Interpreter:''' [[perl]] 5.8.6 |
'''Interpreter:''' [[perl]] 5.8.6 |
||
use Sys::Hostname; |
use Sys::Hostname; |
||
Line 38: | Line 33: | ||
$name = hostname; |
$name = hostname; |
||
== |
=={{header|Pop11}}== |
||
[[Category:Pop11]] |
|||
lvars host = sys_host_name(); |
lvars host = sys_host_name(); |
||
== |
=={{header|Python}}== |
||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.5 |
'''Interpreter:''' [[Python]] 2.5 |
||
Line 50: | Line 42: | ||
host = socket.gethostname() |
host = socket.gethostname() |
||
== |
=={{header|Tcl}}== |
||
[[Category:Tcl]] |
|||
The basic introspection tool in TCL is the <tt>info</tt> command. It can be used to find out about the version of the current Tcl or Tk, the available commands and libraries, variables, functions, the level of recursive interpreter invocation, and, amongst a myriad other things, the name of the current machine: |
The basic introspection tool in TCL is the <tt>info</tt> command. It can be used to find out about the version of the current Tcl or Tk, the available commands and libraries, variables, functions, the level of recursive interpreter invocation, and, amongst a myriad other things, the name of the current machine: |
||
set hname [info hostname] |
set hname [info hostname] |
||
== |
=={{header|Toka}}== |
||
[[Category:Toka]] |
|||
2 import gethostname |
2 import gethostname |
||
1024 chars is-array foo |
1024 chars is-array foo |
Revision as of 05:49, 13 November 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Find the name of the host on which the routine is running.
C
Compiler: GCC 4.0.1
Standard: POSIX.1
#include <limits.h> #include <unistd.h> int main() { char name[_POSIX_HOST_NAME_MAX+1]; gethostname(name, _POSIX_HOST_NAME_MAX+1); }
C#
System.Net.Dns.GetHostName();
IDL
hostname = GETENV('computername')
Java
String hostname = java.net.InetAddress.getLocalHost().getHostName();
Perl
Interpreter: perl 5.8.6
use Sys::Hostname; $name = hostname;
Pop11
lvars host = sys_host_name();
Python
Interpreter: Python 2.5
import socket host = socket.gethostname()
Tcl
The basic introspection tool in TCL is the info command. It can be used to find out about the version of the current Tcl or Tk, the available commands and libraries, variables, functions, the level of recursive interpreter invocation, and, amongst a myriad other things, the name of the current machine:
set hname [info hostname]
Toka
2 import gethostname 1024 chars is-array foo foo 1024 gethostname foo type