So, you need a way to get your user local IP address? Here is the winsock way.
Drop a Button and two Labels then add the bellow code on your window events:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <System.hpp> #include <Winsock2.h> //----------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { WORD wVersionRequested; WSAData wsaData; wVersionRequested = MAKEWORD(1,1); WSAStartup(wVersionRequested,&wsaData); } //----------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { char Buf[256]={0}; hostent *p=gethostbyname(Buf); //user ip Label1->Caption=(inet_ntoa)(*((in_addr*)p->h_addr_list[0])); //user computer name Label2->Caption=p->h_name; } //----------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender) { WSACleanup; } //----------------------------------------------------------------- |
Related links:
- Pv6 addresses: RFC 4291
- Ip Address (@ Wikipedia)
Programmers should be trusted. If your brain surgeon told you the operation you need takes five hours, would you pressure him to do it in three? 