当前位置:天才代写 > tutorial > C语言/C++ 教程 > 取恰当地internet呆板的名字及IP地点

取恰当地internet呆板的名字及IP地点

2017-11-04 08:00 星期六 所属: C语言/C++ 教程 浏览:519

下面的例子利用Winsock API取恰当田主机的名字及地点

void __fastcall TForm1::Button1Click(TObject *Sender)
{
hostent *p;
char s[128];
char *p2;
//Get the computer name
gethostname(s, 128);
p = gethostbyname(s);
Memo1->Lines->Add(p->h_name);
//Get the IpAddress
p2 = inet_ntoa(*((in_addr *)p->h_addr));
Memo1->Lines->Add(p2);
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
WORD wVersionRequested;
WSADATA wsaData;
//Start up WinSock
wVersionRequested = MAKEWORD(1, 1);
WSAStartup(wVersionRequested, &wsaData);
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
WSACleanup();
}

 

    关键字:

天才代写-代写联系方式