Raz-Soft » Blog Archive » Get User IP address Buy Cheap Software
Cleo se intoarce cu un nou videoclip »
« Decapitare la metrou (Piaţa Gorjului)

Get User IP address

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:

    C++:
    1. #include <System.hpp>
    2. #include <Winsock2.h>
    3.  
    4. //-----------------------------------------------------------------
    5. void __fastcall TForm1::FormCreate(TObject *Sender)
    6. {
    7.    WORD wVersionRequested;
    8.    WSAData wsaData;
    9.    wVersionRequested = MAKEWORD(1,1);
    10.    WSAStartup(wVersionRequested,&wsaData);
    11. }
    12. //-----------------------------------------------------------------
    13. void __fastcall TForm1::Button1Click(TObject *Sender)
    14. {
    15.     char Buf[256]={0};
    16.     hostent *p=gethostbyname(Buf);
    17.     //user ip
    18.     Label1->Caption=(inet_ntoa)(*((in_addr*)p->h_addr_list[0]));
    19.     //user computer name
    20.     Label2->Caption=p->h_name;
    21. }
    22.  
    23. //-----------------------------------------------------------------
    24.  
    25. void __fastcall TForm1::FormDestroy(TObject *Sender)
    26. {
    27.     WSACleanup;
    28. }
    29.  
    30. //-----------------------------------------------------------------

Related links:

related things:

Author: Raz | On June 16th, 2007 | C/C++, C++ Builder, [ En ] | No Comments

Q: So what can I do next?
A: You can Buy me a Beer or Coffee. You can say Hi! or peek on the related stuff. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> and all YM emotions