邀请大家来使用龙芯8089D小本远程学习C++

hongwenjun 2013-12-23 01:16:18
机器情况见发到龙芯论坛的帖子
买了8089D玩了几天,做成了服务器

http://goo.gl/kX9WKW 服务器的照片
http://goo.gl/UGeU3x 服务器网址
http://goo.gl/maps/NGMkm 服务器的家


远程登陆可以用 putty.exe 登陆 http://goo.gl/seJFII 下载
[code=c]
SSH: cb@sRGB.vicp.net
密码:codeblocks
[code=c]

或者安装强大的 MsysGit 。

相关文章:https://code.google.com/p/srgb/wiki/cmd 收集的一些资料



...全文
419 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongwenjun 2013-12-28
  • 打赏
  • 举报
回复
在 main函数末尾,添加 自动设置 techno.dnsdynamic.com网址密码 的脚本 完成工具的制作
int main(int argc, char* argv[])
{
 
 /*   ....   */


    // 自动设置 techno.dnsdynamic.com网址密码

    string cmdline = "wget --http-user=帐户  --http-passwd=密码 --no-check-certificate -q -O /tmp/techno.dnsdynamic.com"
                     "https://www.dnsdynamic.org/api/?hostname=techno.ns360.info\\&myip=";
    cmdline += it->second;
    system(cmdline.c_str());
    system("cat /tmp/techno.ns360.info");

    return 0;
}
使用 linux 定时执行任务功能,实现自动更新IP,完成报告 { 2013年 12月 28日 星期六 07:00:01 CST <div>techno.dnsdynamic.com WAN<span> IP: nochg 39.186.177.142</span> 服务器正常工作</div> 2013年 12月 28日 星期六 08:00:01 CST <div>techno.dnsdynamic.com WAN<span> IP: nochg 39.186.177.142</span> 服务器正常工作</div> 2013年 12月 28日 星期六 09:00:01 CST <div>techno.dnsdynamic.com WAN<span> IP: nochg 39.186.177.142</span> 服务器正常工作</div> 2013年 12月 28日 星期六 10:00:01 CST <div>techno.dnsdynamic.com WAN<span> IP: good 112.12.120.165 112.12.120.165</span> 服务器正常工作</div> }
hongwenjun 2013-12-28
  • 打赏
  • 举报
回复
把脚本写到 C++ 程序里,现在一个可执行文件就可以运行了 -d 或者 http 开头的网址 命令参数可选
#define PCRE_STATIC // 静态库编译选项

#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcre.h"
#define OVECCOUNT 30 /* should be a multiple of 3 */
using namespace std;

bool DEBUG_MODE = 0;

std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group);

std::string& load_string(std::string& str, fstream& infile)  // 加载文件到string
{
    std::stringstream ss;
    ss << infile.rdbuf();
    str = ss.str();
    return str;
}

void initializer_webdata(void)
{
    system("touch /tmp/getwanip.txt");
//  system("curl -s 192.168.1.1 | grep ipinfo >>/tmp/getwanip.txt");
    system("curl -s http://www.ip138.com/ips1388.asp | grep ip_add.asp  >>/tmp/getwanip.txt");
    system("curl -s http://ns1.dnspod.net:6666    >>/tmp/getwanip.txt");
    system("echo \"  \"  >>/tmp/getwanip.txt");
//    system("curl -s http://myip.dnsdynamic.org/  >>/tmp/getwanip.txt");

    if (DEBUG_MODE) {
        system("cat /tmp/getwanip.txt");
        cout << "\n----------------------初始化网络IP数据完成!----------------------\n";
    }
}



//  g++ -std=c++0x -lpcre -o getwanip   编译选项

int main(int argc, char* argv[])
{
    string option_url;
    for (int i = 0 ; i != argc ; i++)
        option_url = option_url + " " + argv[i] ;

    if (option_url.find("-d") != string::npos)
        DEBUG_MODE = 1;

    if (option_url.find("http") != string::npos) {
        string cmdline = "curl -s ";
        cmdline += option_url.substr(option_url.find("http"));
        cmdline += " >/tmp/getwanip.txt";
        system("touch /tmp/getwanip.txt");
        system(cmdline.c_str());

        if (DEBUG_MODE) {
            cout << cmdline << endl;
            system("cat /tmp/getwanip.txt");
            cout << "\n----------------------初始化网络IP数据完成!----------------------\n";
        }
    } else
        initializer_webdata();

    std::fstream fs("/tmp/getwanip.txt", std::fstream::in);
    std::string  src;  // 收集的网络 wanip数据
    std::string  reg  = "(\\d+\\.\\d+\\.\\d+\\.\\d+)";     // 简单匹配IP地址正则公式
    load_string(src, fs);
    fs.close();
   remove("/tmp/getwanip.txt");

    std::string ipaddr;
    regex_get_group(src, reg , 1 , ipaddr);
    if (ipaddr == "")
        return -1;

    std::map<string, int> map_wanip;
    while (ipaddr != "") {
        if (DEBUG_MODE)
            cout << ipaddr << endl;;
        ++map_wanip[ipaddr];
        src = src.substr(src.find(ipaddr) + ipaddr.size());
        regex_get_group(src, reg , 1 , ipaddr);
    }

    std::map< int , string> re_wanip;  // 按计数器重排IP地址MAP容器
    for (auto it = map_wanip.begin(); it != map_wanip.end() ; ++it) {
        re_wanip.insert(make_pair(it->second , it->first));
    }

    auto it = re_wanip.begin(); // 最大值排最后
    cout << it->second;
    return 0;
}

std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group)
{
   /*   .............  */
}
max_min_ 2013-12-26
  • 打赏
  • 举报
回复
引用 7 楼 hongwenjun 的回复:
http://www.dnsdynamic.org/api.php 申请的备份域名是 sRGB.x64.me 可以网页API更新IP地址

 A simple example to update a domain using the API directly;
 https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1
实际写了一个Shell 脚本可以工作

root@debian:~# cat ip.sh
#!/bin/bash
#
wget --http-user=帐号   --http-passwd=密码 --no-check-certificate \
-q -O ip.txt \
https://www.dnsdynamic.org/api/?hostname=srgb.x64.me\&myip=39.187.212.8

接下来,准备写个C/C++程序小工具,调用wget和grep 自动完成脚本的工作
hongwenjun 2013-12-26
  • 打赏
  • 举报
回复
http://www.dnsdynamic.org/api.php 申请的备份域名是 sRGB.x64.me 可以网页API更新IP地址

 A simple example to update a domain using the API directly;
 https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1
实际写了一个Shell 脚本可以工作

root@debian:~# cat ip.sh
#!/bin/bash
#
wget --http-user=帐号   --http-passwd=密码 --no-check-certificate \
-q -O ip.txt \
https://www.dnsdynamic.org/api/?hostname=srgb.x64.me\&myip=39.187.212.8

接下来,准备写个C/C++程序小工具,调用wget和grep 自动完成脚本的工作
hongwenjun 2013-12-26
  • 打赏
  • 举报
回复
移动网络,很多网站获取 WAN: IP 不是很正确, 万网的可以正确获取
wget -q -O myip.txt http://www.net.cn/static/customercare/yourip.asp
grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' myip.txt
我实际是从 网关路由器获取的,路由器刷的 DD-WRT 系统
root@debian:~# cat srgb_wanip.sh

#!/bin/bash

wget -q 192.168.1.1 -O /tmp/ip.tmp
date  >>/var/www/ip/index.html
echo " sRGB.vip.net 服务器正常工作" >>/var/www/ip/index.html
grep -e ipinfo /tmp/ip.tmp >>/var/www/ip/index.html
rm /tmp/ip.tmp
然后使用 定时每小时执行一次脚本 http://srgb.vicp.net/ip/
hongwenjun 2013-12-26
  • 打赏
  • 举报
回复
getwanip.sh 获取一些wanip数据,有正确,有错误
#!/bin/bash

touch /tmp/getwanip.txt

# 移动网络测试正确的
curl -s 192.168.1.1 | grep ipinfo >>/tmp/getwanip.txt              #  如果DD-WRT的路由器这个最方便
curl -s http://www.ip138.com/ips1388.asp | grep ip_add.asp  >>/tmp/getwanip.txt
curl -s http://ns1.dnspod.net:6666    >>/tmp/getwanip.txt
echo "  "  >>/tmp/getwanip.txt
curl -s http://www.net.cn/static/customercare/yourip.asp | grep ip   >>/tmp/getwanip.txt   #  今天挂了

#  移动网络不正确
curl -s http://myip.dnsdynamic.org/  >>/tmp/getwanip.txt
echo "  "  >>/tmp/getwanip.txt
curl -s http://ip.3322.net/          >>/tmp/getwanip.txt 
echo "  "  >>/tmp/getwanip.txt
curl -s -I http://www.alibaba.com | grep ali_apache_id    >>/tmp/getwanip.txt     #  移动网络不正确
自己写工具,使用PCRE 再次检查IP,结果最多的肯定是 wanip
#define PCRE_STATIC // 静态库编译选项

#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include "pcre.h"
#define OVECCOUNT 30 /* should be a multiple of 3 */
using namespace std;

std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group);

std::string& load_string(std::string& str, fstream& infile)  // 加载文件到string
{
    std::stringstream ss;
    ss << infile.rdbuf();
    str = ss.str();
    return str;
}

//  g++ -std=c++0x -lpcre   编译选项

int main()
{
    std::fstream fs("/tmp/getwanip.txt", std::fstream::in);
    std::string  src;  // 收集的网络 wanip数据
    std::string  reg  = "(\\d+.\\d+.\\d+.\\d+)";     // 简单匹配IP地址正则公式
    load_string(src, fs);
    fs.close();

    std::string ipaddr;
    regex_get_group(src, reg , 1 , ipaddr);
    if (ipaddr == "")
        return -1;

    std::map<string, int> map_wanip;
    while (ipaddr != "") {
        //      cout << ipaddr << endl;;
        ++map_wanip[ipaddr];
        src = src.substr(src.find(ipaddr) + ipaddr.size());
        regex_get_group(src, reg , 1 , ipaddr);
    }

    std::map< int , string> re_wanip;  // 按计数器重排IP地址MAP容器
    for (auto it = map_wanip.begin(); it != map_wanip.end() ; ++it) {
        re_wanip.insert(make_pair(it->second , it->first));
    }

    auto it = re_wanip.rbegin(); // 最大值排最后
    cout << it->second;
    return 0;
}

std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group)
{
    pcre*  re;
    const char* error;
    int  erroffset;
    int  ovector[OVECCOUNT];  // 用来返回匹配位置偏移量的数组

//    printf("原字符串 : %s\n", src.c_str());
//    printf("匹配公式 : \"%s\"\n", pattern.c_str());

    re = pcre_compile(pattern.c_str(),   // pattern, 输入参数,将要被编译的字符串形式的正则表达式
                      0,            // options, 输入参数,用来指定编译时的一些选项
                      &error,       // errptr, 输出参数,用来输出错误信息
                      &erroffset,   // erroffset, 输出参数,pattern中出错位置的偏移量
                      NULL);        // tableptr, 输入参数,用来指定字符表,一般情况用NULL
    // 返回值:被编译好的正则表达式的pcre内部表示结构

    int rc = pcre_exec(re,            // code, 输入参数,用pcre_compile编译好的正则表达结构的指针
                       NULL,          // extra, 输入参数,用来向pcre_exec传一些额外的数据信息的结构的指针
                       src.c_str(),           // subject, 输入参数,要被用来匹配的字符串
                       src.size(),  // length, 输入参数, 要被用来匹配的字符串的指针
                       0,             // startoffset, 输入参数,用来指定subject从什么位置开始被匹配的偏移量
                       0,             // options, 输入参数, 用来指定匹配过程中的一些选项
                       ovector,       // ovector, 输出参数,用来返回匹配位置偏移量的数组
                       OVECCOUNT);    // ovecsize, 输入参数, 用来返回匹配位置偏移量的数组的最大大小
    // 返回值:匹配成功返回非负数,没有匹配返回负数

    if (rc < 0) {
        pcre_free(re);
        return str_group = "";

    }

//    for (int i = 0; i < rc; i++) {
//        int substring_length = ovector[2 * i + 1] - ovector[2 * i]; // 字符串结束的索引 减去 开始的索引,就是字符串长度
//        string str = src.substr(ovector[2 * i] , substring_length); // 分别取出每个捕获分组
//        cout << "捕获分组: " << i << "\t" << str << endl;
//    }

    int substring_length = ovector[2 * group + 1] - ovector[2 * group]; // 字符串结束的索引 减去 开始的索引,就是字符串长度
    str_group = src.substr(ovector[2 * group] , substring_length);      // 获得捕获分组

    pcre_free(re);                     // 编译正则表达式re 释放内存
    return str_group;
}
hongwenjun 2013-12-26
  • 打赏
  • 举报
回复
linux 获取公网IP 的几个通用方法
http://ip.3322.net/                                     // 移动网络不正确
curl -s -I http://www.alibaba.com | grep ali_apache_id  // 移动网络不正确
http://www.net.cn/static/customercare/yourip.asp        // 今天挂了
curl -s http://www.ip138.com/ips1388.asp | grep ip_add.asp
curl -s http://ns1.dnspod.net:6666
curl -s 192.168.1.1 | grep ipinfo                       // 如果DD-WRT的路由器这个最方便
准备写的工具的,最后选择使用 PCRE正则库,下面是原始版本

#define PCRE_STATIC // 静态库编译选项
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include "pcre.h"
#define OVECCOUNT 30 /* should be a multiple of 3 */
using namespace std;

std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group);

int main()
{



    string  src = "<div class=\"info\">WAN<span id=\"ipinfo\"> IP: 39.187.212.8</span></div>";  // 要被用来匹配的字符串
    string  reg  = "<span.*IP: (\\d+.\\d+.\\d+.\\d+)</span>";              // 将要被编译的字符串形式的正则表达式

    cout << regex_get_group(src, reg , 1 , src);
    return 0;
}
http://ip.3322.net/                                     // 移动网络不正确
curl -s -I http://www.alibaba.com | grep ali_apache_id  // 移动网络不正确
http://www.net.cn/static/customercare/yourip.asp        // 今天挂了
curl -s http://www.ip138.com/ips1388.asp | grep ip_add.asp
curl -s http://ns1.dnspod.net:6666
curl -s 192.168.1.1 | grep ipinfo                       // 如果DD-WRT的路由器这个最方便
std::string& regex_get_group(const std::string& src , const std::string& pattern ,
                             int group , std::string& str_group)
{
    pcre*  re;
    const char* error;
    int  erroffset;
    int  ovector[OVECCOUNT];  // 用来返回匹配位置偏移量的数组

//    printf("原字符串 : %s\n", src.c_str());
//    printf("匹配公式 : \"%s\"\n", pattern.c_str());

    re = pcre_compile(pattern.c_str(),   // pattern, 输入参数,将要被编译的字符串形式的正则表达式
                      0,            // options, 输入参数,用来指定编译时的一些选项
                      &error,       // errptr, 输出参数,用来输出错误信息
                      &erroffset,   // erroffset, 输出参数,pattern中出错位置的偏移量
                      NULL);        // tableptr, 输入参数,用来指定字符表,一般情况用NULL
    // 返回值:被编译好的正则表达式的pcre内部表示结构

    int rc = pcre_exec(re,            // code, 输入参数,用pcre_compile编译好的正则表达结构的指针
                       NULL,          // extra, 输入参数,用来向pcre_exec传一些额外的数据信息的结构的指针
                       src.c_str(),           // subject, 输入参数,要被用来匹配的字符串
                       src.size(),  // length, 输入参数, 要被用来匹配的字符串的指针
                       0,             // startoffset, 输入参数,用来指定subject从什么位置开始被匹配的偏移量
                       0,             // options, 输入参数, 用来指定匹配过程中的一些选项
                       ovector,       // ovector, 输出参数,用来返回匹配位置偏移量的数组
                       OVECCOUNT);    // ovecsize, 输入参数, 用来返回匹配位置偏移量的数组的最大大小
    // 返回值:匹配成功返回非负数,没有匹配返回负数

    if (rc < 0) {
        pcre_free(re);
        return str_group = "";

    }

//    for (int i = 0; i < rc; i++) {
//        int substring_length = ovector[2 * i + 1] - ovector[2 * i]; // 字符串结束的索引 减去 开始的索引,就是字符串长度
//        string str = src.substr(ovector[2 * i] , substring_length); // 分别取出每个捕获分组
//        cout << "捕获分组: " << i << "\t" << str << endl;
//    }

    int substring_length = ovector[2 * group + 1] - ovector[2 * group]; // 字符串结束的索引 减去 开始的索引,就是字符串长度
    str_group = src.substr(ovector[2 * group] , substring_length);      // 获得捕获分组

    pcre_free(re);                     // 编译正则表达式re 释放内存
    return str_group;
}

jiandingzhe 2013-12-26
  • 打赏
  • 举报
回复
楼主啊,Ping不到你的地址
lee_鹿游原 2013-12-23
  • 打赏
  • 举报
回复
这是在做推销么..
hongwenjun 2013-12-23
  • 打赏
  • 举报
回复
279元 加 17远 顺丰快递
  • 打赏
  • 举报
回复
这多少钱啊?
昵称很不好取 2013-12-23
  • 打赏
  • 举报
回复
这就是传说中的国产神器?
别逗我乐 2013-12-23
  • 打赏
  • 举报
回复
大神,给力,顶一个

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧