(C++) WtGetIpAddress
February 24, 2017 · View on GitHub
(C++) WtGetIpAddress



Wt FAQ on how to obtain the client's (that is: any person that browser your Wt website from any place in the world) IP address.
- View a screenshot of 'CppWtGetIpAddress' (png)
- Download the source code of 'CppWtGetIpAddress' (zip)
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
Boost: version 1.55
Qt: version 5.4.1 (32 bit)
STL: GNU ISO C++ Library, version
4.9.2
Wt: version 3.3.3
Qt project file: ./CppWtGetIpAddress/CppWtGetIpAddress.pro
#------------------------------------------------- # # Project created by QtCreator 2011-05-15T20:17:39 # #------------------------------------------------- QT += core QT -= gui LIBS += -lwt -lwthttp -lboost_program_options INCLUDEPATH += ../../Classes/CppWtAutoConfig TARGET = CppWtGetIpAddress CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp \ ../../Classes/CppWtAutoConfig/wtautoconfig.cpp HEADERS += \ ../../Classes/CppWtAutoConfig/wtautoconfig.h
./CppWtGetIpAddress/main.cpp
#include <Wt/WApplication> #include <Wt/WEnvironment> #include <Wt/WContainerWidget> #include <Wt/WLabel> //--------------------------------------------------------------------------- #include "wtautoconfig.h" //--------------------------------------------------------------------------- const std::string GetIpAddress(const Wt::WEnvironment& env) { return env.clientAddress(); } //--------------------------------------------------------------------------- struct WtDialog : public Wt::WContainerWidget { WtDialog(const std::string& ip_address) { new Wt::WLabel( std::string("Client IP address: ") + ip_address,this); } }; //--------------------------------------------------------------------------- struct WtApplication : public Wt::WApplication { WtApplication(const Wt::WEnvironment& env) : Wt::WApplication(env) { this->setTitle("CppWtGetIpAddress"); this->useStyleSheet("wt.css"); this->enableUpdates(); const std::string ip_address = env.clientAddress(); root()->addWidget(new WtDialog(ip_address)); } }; //--------------------------------------------------------------------------- Wt::WApplication * createApplication(const Wt::WEnvironment& env) { return new WtApplication(env); } //--------------------------------------------------------------------------- int main(int argc, char **argv) { WtAutoConfig a(argc,argv,createApplication); WtAutoConfig::SaveDefaultStylesheet(); return a.Run(); } //---------------------------------------------------------------------------