雅荷心语博客
雅荷心语
心之所向便是光
  • 首页
  • 前端之旅
  • 后端之路
  • 软件工具
  • 心灵鸡汤
  • 心路历程
  • 视频资料
  • 关于我们
    • 关于我
    • 关于我
  • 微信平台
    • 业务合作
  • 首页
  • 前端之旅
  • 后端之路
  • 软件工具
  • 心灵鸡汤
  • 心路历程
  • 视频资料
  • 关于我们
    • 关于我
    • 关于我
  • 微信平台
    • 业务合作
  • 关注本站
    • 微信
    • 微博
    • 腾讯微博
    • Twitter
    • Facebook
    • RSS订阅
Hi, 请登录     我要注册     找回密码

Electron和React结合开发代理IP获取及检测工具

2019-08-05 分类:前端之旅 阅读(1997) 评论(0)

近期, 为了学习React相关知识,简单开发了一个小工具, 使用的技术栈是:

Electron + React + PHP, UI框架使用了element, 大概长这样!

Snipaste_2019-08-05_11-46-34

具体的开发思路如下

首先我使用react启动服务, 然后使用 Electron 打开服务URL,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 1237,
    height: 760,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      javascript: true,
      plugins: true,
      nodeIntegration: true, // 是否集成 Nodejs
      webSecurity: false,
    }
  })
  // and load the index.html of the app.
  // mainWindow.loadFile('index.html')
  if (isModel) {
    mainWindow.loadURL(url.format({
      pathname: path.join(__dirname, './build/index.html'),
      protocol: 'file:',
      slashes: true
    }))
  } else {
    mainWindow.loadURL('http://localhost:3000/')
  }
  // TODO 打开控制台
  mainWindow.webContents.openDevTools()
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })
  winApp.init(mainWindow, app)
}
app.on('ready', createWindow)

当借口请求完成之后, 循环代理IP, 使用 Electron 的 remote 来动态调用 Electron 里面定义的检测服务! 检测完成之后, 挨个更新 数据, 显示结果

1
2
3
4
5
6
7
8
9
10
checkProxyFun (val, index) {
const remote = window.electron.remote;
let testUrl = 'https://www.baidu.com/';
remote.app.proxyTest(testUrl,'http://'+val.proxy)
.then((res,body,head)=> {
this.setProxy(index,'check_result', 1)
}).catch(e =>{
this.setProxy(index,'check_result',2)
});
}

remote 方法定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Created by PhpStorm.
* User:  iyahe@qq.com (天明)
* Date: 2019/8/1 0001
* Time: 下午 18:10
* Description:
*/
var request = require('superagent');
var agents = require('./config/ua')
require('superagent-proxy')(request);
let proxy = {
init (web, app) {
// TODO 挂载方法到 app 模块上,供 remote 模块使用
app.proxyTest = function (
$url, $proxy = '', $option = {
timeout: {
response: 3000,
deadline: 6000
}
}) {
// TODO 随机获取一个ua
let userAgent = agents[parseInt(Math.random() * agents.length)];
return new Promise((resolve, reject) => {
request
.get($url)
.timeout($option.timeout)
.set({ 'User-Agent': userAgent })
.proxy($proxy)
.end(function (err, res) {
if (err) {
reject(err)
} else {
resolve(res.status, res.body, res.headers)
}
});
})
}
}
}
 
 
exports.default = proxy

目前项目只完成一半功能, 后面有时间, 再完善其他

项目地址: https://gitee.com/shala/Electron-React

分享到:更多 ()

相关推荐

  • AI 编辑器 cursor 如何禁止自动更新
  • AI 编辑器 cursor 工具栏改成和 vscode 一样的左侧 竖向展示
  • nodejs 脚本打包为可执行文件
  • 初学 python 笔记
  • nodejs 同时运行多个脚本
  • 让你的照片动起来
  • vue工程项目动态加载umd.js实践
  • 使用 shell 检测目标服务器是否异常
关于我

小天明 北京·朝阳 前端搬砖工程师

碎碎念):(来自公众号)

热门文章

  • 踩坑记录——iphone上safari开启隐身模式时localStorage变为只读-雅荷心语博客踩坑记录——iphone上safari开启隐身模式时localStorage变为只读2017-02-21评论(4)
  • 程序员是怎样一群人-雅荷心语博客程序员是怎样一群人2015-12-08评论(3)
  • 百度你个大毒瘤 - 吐糟博客这几天打不开事情-雅荷心语博客百度你个大毒瘤 – 吐糟博客这几天打不开事情2015-12-28评论(2)
  • PHP 非对称加密 openssl 加密及解密方法-雅荷心语博客PHP 非对称加密 openssl 加密及解密方法2016-05-17评论(2)
  • PHPStorm10 下载安装破解汉化-雅荷心语博客PHPStorm10 下载安装破解汉化2015-12-15评论(2)
2025年7月
一 二 三 四 五 六 日
« 六    
 123456
78910111213
14151617181920
21222324252627
28293031  

最新评论

  • 前端小武 8年前 (2017-04-06)说:
    我看到了layer
  • 丁艳平 8年前 (2017-03-03)说:
  • Dawn 9年前 (2016-09-16)说:
    call_user_func_array最后的例子是错哦,你用bc方法去调用类里 另外一个方法就知道问题所在了。情况1.调用非静态方法 第一个参数应该传[类的实例,调用方法] (既然有类实例了直接-&
  • Dawn 9年前 (2016-06-21)说:
    tp框架设置了全局捕获异常的,这也没什么。坑的是 他捕获了异常。然后全部返回404。。。不知道的 还以为自己网站被删除了
  • Dawn 9年前 (2016-05-17)说:
    构造函数里的判断 用异常机制可能更好一些

其他类型

  • 芊云全景
  • 配音兔AI配音神器

博客类型

  • 芊云全景
  • 配音兔AI配音神器

左邻右舍

  • 易水寒
  • 楼教主
  • 芊云全景
  • 贤心
  • 配音兔AI配音神器

雅荷心语博客 -心之所向便是光

联系我们关于我们

© 2025 雅荷心语博客   网站地图