日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt-IP地址查询工具(使用HTTP GET方法)

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt-IP地址查询工具(使用HTTP GET方法) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

程序運行截圖如下:

?

原理(原理和爬蟲一樣):

1.偽造HTTP數據封包頭

2.處理爬下來的網站

?

關鍵代碼如下:

inquireip.h

#ifndef INQUIREIP_H #define INQUIREIP_H#include <QObject> #include <QTcpSocket>class InquireIp : public QObject {Q_OBJECT public:explicit InquireIp(QObject *parent = 0);void startConnect(const QString host,quint16 port);void setIp(const QString ip);public slots:void onConnected();void onReadyRead();signals:void sendIpLocation(QString msg);protected:void disposeHTTPContent(QString msg);private:QTcpSocket *m_socket;QString m_ip;QString m_httpContent; };#endif // INQUIREIP_H

inquireip.cpp

#include "inquireip.h" #include <QDebug> #include <QTextCodec> #include <QByteArray>InquireIp::InquireIp(QObject *parent) :QObject(parent),m_socket(0),m_ip("") {m_ip="127.0.0.1"; }void InquireIp::startConnect(const QString host, quint16 port) {m_socket=new QTcpSocket(this);connect(m_socket,SIGNAL(connected()),this,SLOT(onConnected()));connect(m_socket,SIGNAL(readyRead()),this,SLOT(onReadyRead()));m_socket->connectToHost(host,port); }void InquireIp::setIp(const QString ip) {m_ip=ip; }void InquireIp::onConnected(){QString msg=QString("GET /ips138.asp?ip=%1&action=2 HTTP/1.1\r\n""Host: www.ip138.com\r\n""User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0\r\n""Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n""Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\r\n""Accept-Encoding: gzip, deflate\r\n""Referer: http://www.ip138.com/\r\n""Cookie: pgv_pvi=1815538688; pgv_si=s3422986240; ASPSESSIONIDCASTDCQB=CNPDBLMDPKKBEFLKKAMALGIK; ASPSESSIONIDQACDQCBR=DOAMDOGDCEGHLCPBBOIHKHFI\r\n""Connection: keep-alive\r\n""Upgrade-Insecure-Requests: 1\r\n\r\n").arg(m_ip);m_socket->write(msg.toLatin1());}void InquireIp::onReadyRead() {QTextCodec *codec = QTextCodec::codecForName("gb2312");QString qstr = codec->toUnicode(m_socket->readAll());int q1=qstr.indexOf("<li>");int q2=qstr.indexOf("</li>");QString str=qstr.mid(q1+9,q2-q1);QStringList strList=str.split(" ");if(strList[0]=="")return;emit sendIpLocation(strList[0]); }void InquireIp::disposeHTTPContent(QString msg) {}

?

總結

以上是生活随笔為你收集整理的Qt-IP地址查询工具(使用HTTP GET方法)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。