| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using Org.BouncyCastle.Ocsp;
- using System.Text.Json;
- using System.Runtime.InteropServices;
- using TencentCloud.Scf.V20180416.Models;
- using Quartz.Impl.AdoJobStore.Common;
- using TencentCloud.Gaap.V20180529.Models;
- using System.Net;
- using TencentCloud.Ie.V20200304.Models;
- using TencentCloud.Soe.V20180724.Models;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [MyAuthorize("admin")]
- [Route("api/[controller]/[action]")]
- public class ProxyController : ControllerBase
- {
- readonly IAuthorizationProvider provider = new AdminProvider();
- protected IHttpContextAccessor _accessor;
- public ProxyController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public ActionResult get()
- {
- var list = new DBContext.Table("proxy_nodes")
- .Where("status=@status", new { status = 1 })
- .Select<ProxyNodesDTO>();
- // 参考数据
- //61 1 6 品阅245 品阅辅助网卡 bj http http://172.21.127.245:33128 molilian Bhquvmkn8zLO36lGjuqk 2024-04-09 14:25:53 2024-04-09 14:25:56
- //59 1 6 品阅243 品阅辅助网卡 bj http http://172.21.127.243:33128 molilian Bhquvmkn8zLO36lGjuqk 2024-04-09 14:25:53 2024-04-09 14:25:56
- foreach (var proxy in list)
- {
- //通过 curl myip.ipip.net检测proxy可访问行
- }
- var tasks = new List<Task<int>>
- {
- Task.Run(()=>{ })
- };
- // 等待所有任务完成
- Task.WhenAll(tasks).Wait();
- return new APIResult(new { list });
- }
- [HttpGet]
- public async Task<ActionResult> ChangePublicIpByName(string nodeName)
- {
- var proxy_node = new DBContext.Table("proxy_nodes").Get<dynamic>("name=@nodeName", new { nodeName });
- if (proxy_node == null) return new APIResult(new { success = false, msg = "没有匹配的 proxy_nodes 记录" });
- int aliyun_id = proxy_node.aliyun_id;
- string proxy_server = proxy_node.server;
- var account = new DBContext.Table("aliyun_pool").Get<AliyunPoolDTO>(aliyun_id);
- if (account == null) return new APIResult(new { success = false, msg = "没有匹配的 aliyun_pool 记录" });
- var uri = new Uri(proxy_server);
- string privateIp = uri.Host;
- AliyunCore core = new AliyunCore(account);
- var success = core.ChangePublicIp(privateIp);
- return new APIResult(new { success = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> ChangePublicIp(int id)
- {
- id = id >= 20000 ? id - 20000 : id;
- var proxy_node = new DBContext.Table("proxy_nodes").Get<dynamic>(id);
- if (proxy_node == null) return new APIResult(new { success = false, msg = "没有匹配的 proxy_nodes 记录" });
- int aliyun_id = proxy_node.aliyun_id;
- string proxy_server = proxy_node.server;
- var account = new DBContext.Table("aliyun_pool").Get<AliyunPoolDTO>(aliyun_id);
- if (account == null) return new APIResult(new { success = false, msg = "没有匹配的 aliyun_pool 记录" });
- var uri = new Uri(proxy_server);
- string privateIp = uri.Host;
- AliyunCore core = new AliyunCore(account);
- var success = core.ChangePublicIp(privateIp);
- return new APIResult(new { success = "ok" });
- }
- }
- }
|