update20190107
20190107 V1.0 正式版--- 修复PostgreSQL环境变量文件名称配置错误,导致无法正确加载环境变量配置。 新增优化代理功能,可在代理中心设置Socks5/HTTSP/HTTPS代理,可以固定单个代理,也可能从代理次中随机选择。
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using SuperSQLInjection.model;
|
||||
|
||||
namespace tools
|
||||
{
|
||||
@@ -189,11 +190,6 @@ namespace tools
|
||||
sw = new StreamWriter(fs_dir);
|
||||
|
||||
sw.WriteLine(log);
|
||||
|
||||
sw.Close();
|
||||
|
||||
fs_dir.Close();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -213,5 +209,103 @@ namespace tools
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 注意:vals为空或null会清空代理
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="vals"></param>
|
||||
public static void SaveProxyList(String path, Dictionary<String,Proxy>.ValueCollection vals)
|
||||
{
|
||||
|
||||
FileStream fs_dir = null;
|
||||
StreamWriter sw = null;
|
||||
try
|
||||
{
|
||||
if (vals != null && vals.Count > 0)
|
||||
{
|
||||
fs_dir = new FileStream(path, FileMode.Create, FileAccess.Write);
|
||||
sw = new StreamWriter(fs_dir, Encoding.UTF8);
|
||||
foreach(Proxy proxy in vals)
|
||||
{
|
||||
String line = proxy.host + "\t" + proxy.port + "\t" + proxy.proxyType + "\t" + proxy.username + "\t" + proxy.password + "\t" + proxy.isOk + "\t" + proxy.useTime + "\t" + proxy.checkTime;
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//如果为空,则删除代理
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Tools.SysLog("保存代理池发生异常!" + e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sw != null)
|
||||
{
|
||||
sw.Close();
|
||||
}
|
||||
if (fs_dir != null)
|
||||
{
|
||||
fs_dir.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Dictionary<String,Proxy> ReadProxyList(String path)
|
||||
{
|
||||
|
||||
Dictionary<String, Proxy> list = new Dictionary<String, Proxy>();
|
||||
FileStream fs_dir = null;
|
||||
StreamReader reader = null;
|
||||
try
|
||||
{
|
||||
fs_dir = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
|
||||
reader = new StreamReader(fs_dir);
|
||||
|
||||
String lineStr;
|
||||
|
||||
while ((lineStr = reader.ReadLine()) != null)
|
||||
{
|
||||
if (!lineStr.Equals(""))
|
||||
{
|
||||
String[] strs = lineStr.Split('\t');
|
||||
if (strs.Length == 8) {
|
||||
Proxy proxy = new Proxy();
|
||||
proxy.host = strs[0];
|
||||
proxy.port= Tools.convertToInt(strs[1]);
|
||||
proxy.proxyType= strs[2];
|
||||
proxy.username = strs[3];
|
||||
proxy.password = strs[4];
|
||||
proxy.isOk = strs[5];
|
||||
proxy.useTime = Tools.convertToInt(strs[6]);
|
||||
proxy.checkTime = strs[7];
|
||||
list.Add(proxy.host + proxy.port, proxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Tools.SysLog("ReadProxyList异常:"+e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
reader.Close();
|
||||
}
|
||||
if (fs_dir != null)
|
||||
{
|
||||
fs_dir.Close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user