Find out my ip address on the internet by Qt
-
What I trying to do is
server_ = new SslServer(this); server_->listen(QHostAddress::AnyIPv4, port); //ftp protocal implementationIs it possible to listen to the other pc if I give them the address I obtain from the "whatismyipaddress.com"?
-
I could get my ip address from this website,is it possible to obtain that address by Qt?
Would like to create a ftp server and let other's connect to my pc, thanks
@tham
I suggest you use a free (signup required though) Webservice (like ipstack.com) for the sake of simplicity.
Use QNetworkAccessManager to make a GET request to their API and parse the JSON response with QJsonDocument.But note the IP is only required if you want to let the clients connect via internet (assuming port forwarding is correctly setup on your router).
For your local LAN IP address you can use:
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); for( int i = 0; i < ipAddressesList.size(); ++i ) { if( ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address() ) qDebug() << ipAddressesList.at(i).toString(); } -
What I trying to do is
server_ = new SslServer(this); server_->listen(QHostAddress::AnyIPv4, port); //ftp protocal implementationIs it possible to listen to the other pc if I give them the address I obtain from the "whatismyipaddress.com"?
@tham Hi,
to add to what @raven-worx said we would need to know more (mainly, as this has been pointed out, are you referring to the public IP address of your Internet node or to the machine assigned local IP?) as use case will differ. Also, additional actions like port forwarding might be required.
Could you please describe what's your intended use case? How would you like your software to work?