zoukankan      html  css  js  c++  java
  • 动态IP获取

    自己用ARM9实现了网络摄像头

    但是家里拨号到ip老是变,导致公网外部老是访问不了。

    所以想了一下,本来想用邮箱做IP记录

     现在直接用php实现

    <?php
    if(isset($_GET["chk"]))
    {
      $file_pointer = fopen("ip","w");
      fwrite($file_pointer,$_SERVER["REMOTE_ADDR"]);
      fclose($file_pointer);

      echo $_SERVER["REMOTE_ADDR"];
    }else{
      echo file_get_contents("ip");
    }

    ?> 

    嵌入式里面每隔5分钟访问ip.php?chk=c

    QT嵌入式代码

    qsetip.h

    #ifndef QSETIP_H

    #define QSETIP_H
    #include <QUrl>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QDebug>
    class QSetIp : public QObject
    {
        Q_OBJECT
    private:
        QUrl url;
        QNetworkAccessManager* qnam;
        QNetworkReply *reply;
        int httpGetId;
        bool httpRequestAborted;
    public:
        explicit QSetIp(QObject *parent = 0);
        void startRequest(QUrl url);
    signals:
        void httpFinish(QString result);
    public slots:
        void httpFinished();
    };
    #endif // QSETIP_H
    
    
    
    

    qsetip.cpp

    #include "qsetip.h"

    QSetIp::QSetIp(QObject *parent) :
            QObject(parent)
    {
    }
    void QSetIp::startRequest(QUrl url)
    {
        qnam = new QNetworkAccessManager(this);
        reply = qnam->get(QNetworkRequest(url));
        connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
    }
    void QSetIp::httpFinished()
    {
        if (httpRequestAborted) {
            QString html = reply->readAll();
            httpFinish(html);
            qDebug()<< html;
            reply = 0;
        }
    }
    
    

    在程序启动 加入

    QTimer *timer = new QTimer(this);

    connect(timer, SIGNAL(timeout()), this, SLOT(runGet()));
    timer->start(5000);

    建立slot

    void MainWindow::runGet()

    {
        setIpClass = new QSetIp(this);
        setIpClass->startRequest(QUrl("http://www.xxxxxx.com/ip.php?chk=1"));
    }


     

  • 相关阅读:
    Oracle学习
    WPF中获取DataGrid列表的选中行Id的方法
    调用MySql存储过程的方法 '增删改查'
    MySql中存储过程的基本增删改查操作
    在WinForm中遍历获取TreeView的节点及其子节点
    WinForm获取MySql数据的基本增删改查
    WinForm中的用户控件实现分页功能
    NGUI之自适应屏幕
    快速排序法
    Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>
  • 原文地址:https://www.cnblogs.com/kenter/p/1827966.html
Copyright © 2011-2022 走看看