導航:首頁 > IDC知識 > get主機

get主機

發布時間:2020-12-21 22:59:23

1、request的getRemoteAddr()和getRemoteHost()方法有什麼區別?

坑先
前一個是獲得客戶端的ip地址
後一個是獲得客戶端的主機

2、TimeZone.getDefault()—獲取主機所處時區的對象。這個主機什麼意思?是本地的意思么?

這個程序,在哪台電腦上運行,就是那台電腦的時區

3、c語言中怎樣讀取當前gethostname值

1、gethostbyname()函數屬於WinSock API庫,而在使用WinSock API之前,必須調用WSA-Startup函數,只有該函數成功返回(表示應用程序與WinSock庫成功地建立起連接),應用程序才可以調用其他Windows Sockets DLL中的函數。當程序將要結束時,又必須調用WSACleanup 函數進行清理工作,以便釋放其佔用的資源。WSACleanup 函數用來結束Windows Sockets DLL的使用。

2、常式:

char hostname[256];
    int iRet = 0;
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2,1),&wsaData)) //調用Windows Sockets DLL
    { 
        printf("Winsock無法初始化! ");
        WSACleanup();
        return 0;
    }
    memset(hostname, 0, 256);
    iRet = gethostname(hostname, sizeof(hostname));
    if(iRet != 0 )
    {
        printf( "get hostname error:%d ", iRet);
    }
    printf("%s ", hostname);

4、急求解 使用gethostname() 的方法

char hostname[256];
int iRet = 0;
WSADATA wsaData;

if (WSAStartup(MAKEWORD(2,1),&wsaData)) //調用Windows Sockets DLL
{
回printf("Winsock無法初始化!答\n");
WSACleanup();
return 0;
}
memset(hostname, 0, 256);
iRet = gethostname(hostname, sizeof(hostname));
if(iRet != 0 )
{
printf( "get hostname error:%d\n", iRet);
}
printf("%s\n", hostname);

5、LINUX下如何用gethostname命令

我的系統里根本沒這個命令。ubuntu 也不提供這個命令……

你 gethostbyname --help 看看幫助。

另外,我版在網上找到的都是 gethostbyname() 這個權 C 函數的使用方法,而不是命令的使用方法……

6、為什麼我vc中調用gethostname都返回-1,得到本機的主機名都會失敗嗎?

調用gethostname之前,源必須成功調用過 WSAStartup 函數,
是用於網路連接獲取主機名
我懷疑你是不是要 使用GetComputerName,來獲取本地計算機的名字。

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
char HostName[80];
void main ()
{
memset(HostName,0,sizeof(HostName));

DWORD i= 80;

GetComputerName(HostName,&i);
printf("%s",HostName);

}

7、python中gethostname得到的主機名是啥?

import socket
socket.gethostname()
# 'hostname'

主機名就是計算來機源的名字(計算機名),網上鄰居就是根據主機名來識別的。這個名字可以隨時更改,在windows操作系統中,從我的電腦屬性的計算機名就可更改。

需要注意的是,主機名和用戶登錄名稱無關。

8、Dns.GetHostName()[0]是什麼意思

Dns 是一個靜態類,它從 Internet 域名系統 (DNS) 檢索關於特定主機的信息。
GetHostName()是Dns類的一個方法,獲得本機電腦的主機名『
例如:
public void DisplayLocalHostName()
{
try {
// Get the local computer host name獲得本機電腦的主機名
String hostName = Dns.GetHostName();
Console.WriteLine("Computer name :" + hostName);
}
catch(SocketException e) {
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
}

9、c語言調用本機ip地址時如何定義gethostname函數

//c++獲取本機IP
#include <stdio.h>
#include <stdlib.h>
#include <WINSOCK2.H>
#pragma comment(lib,"ws2_32.lib")

int getIP(int ,char**)
{

char host_name[255];
if(gethostname(host_name,sizeof(host_name))==SOCKET_ERROR)
{

printf("Error %d when getting local host name\n",WSAGetLastError());
return -1;
}
printf("host name:%s\n",host_name);
struct hostent *phe=gethostbyname(host_name);
if(phe==0)
{

printf("Error host lookup\n");
return -1;

}

for(int i=0;phe->h_addr_list[i]!=0;++i)
{
struct in_addr addr;
memcpy(&addr,phe->h_addr_list[i],sizeof(struct in_addr));
printf("Address %d :%s\n",i,inet_ntoa(addr));

}
return 0;
}
int main(int argc,char *argv[])
{
WSAData wsaData;
if(WSAStartup(MAKEWORD(1,1),&wsaData)!=0)
{

system("pause");
return -1;
}
int result=getIP(argc,argv);
WSACleanup();
system("pause");
return result;
}

10、java里的網路gethostaddress是什麼意思啊?

與get主機相關的知識