Compare commits

..

2 Commits

Author SHA1 Message Date
e5050fd937 20220826 2022-08-26 16:49:18 +08:00
0b38c0ab17 控制台基本版本 2022-08-26 16:38:41 +08:00
9 changed files with 119 additions and 12 deletions

Binary file not shown.

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,55 @@
using System.Text;
namespace AxibugTransfer.Config
{
public struct CfgInfo
{
public int localPort;
public string targetIP;
public int targetPort;
}
public static class Config
{
public static bool LoadConfig(out List<CfgInfo> cfgList)
{
cfgList = new List<CfgInfo>();
try
{
StreamReader sr = new StreamReader(System.Environment.CurrentDirectory + "\\config.cfg", Encoding.Default);
String line;
while (!string.IsNullOrEmpty((line = sr.ReadLine())))
{
if (!line.Contains(":"))
continue;
try
{
CfgInfo cfg = new CfgInfo()
{
localPort = Convert.ToInt32(line.Split(':')[0].Trim()),
targetIP = line.Split(':')[1].Trim(),
targetPort = Convert.ToInt32(line.Split(':')[2].Trim())
};
cfgList.Add(cfg);
}
catch
{
continue;
}
}
sr.Close();
if (cfgList.Count > 0)
return true;
else
return false;
}
catch(Exception ex)
{
Console.WriteLine("配置文件异常:"+ex.ToString());
return false;
}
}
}
}

View File

@ -1,5 +0,0 @@
using AxibugTransfer.Tcp;
new TcpTransfer(80, "Your IP", 8080, true).Start();
Console.ReadLine();

View File

@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugTransfer.Tcp", "AxibugTransfer.Tcp\AxibugTransfer.Tcp.csproj", "{B5A89E34-0283-44CB-8683-8E41888CA949}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AxibugTransfer.Tcp", "AxibugTransfer.Tcp\AxibugTransfer.Tcp.csproj", "{B5A89E34-0283-44CB-8683-8E41888CA949}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugTransfer.Test", "AxibugTransfer.Test\AxibugTransfer.Test.csproj", "{A27FCE74-123D-477C-BB5B-2879D0B39D22}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugTransfer.Config", "AxibugTransfer.Config\AxibugTransfer.Config.csproj", "{A4C29DED-B1B3-4312-8743-A2BF20188618}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugTransfer", "AxibugTransfer\AxibugTransfer.csproj", "{69341276-017A-43F1-BC73-6123013C689F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,10 +19,14 @@ Global
{B5A89E34-0283-44CB-8683-8E41888CA949}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5A89E34-0283-44CB-8683-8E41888CA949}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5A89E34-0283-44CB-8683-8E41888CA949}.Release|Any CPU.Build.0 = Release|Any CPU
{A27FCE74-123D-477C-BB5B-2879D0B39D22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A27FCE74-123D-477C-BB5B-2879D0B39D22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A27FCE74-123D-477C-BB5B-2879D0B39D22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A27FCE74-123D-477C-BB5B-2879D0B39D22}.Release|Any CPU.Build.0 = Release|Any CPU
{A4C29DED-B1B3-4312-8743-A2BF20188618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4C29DED-B1B3-4312-8743-A2BF20188618}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4C29DED-B1B3-4312-8743-A2BF20188618}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4C29DED-B1B3-4312-8743-A2BF20188618}.Release|Any CPU.Build.0 = Release|Any CPU
{69341276-017A-43F1-BC73-6123013C689F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69341276-017A-43F1-BC73-6123013C689F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69341276-017A-43F1-BC73-6123013C689F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69341276-017A-43F1-BC73-6123013C689F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AxibugTransfer.Config\AxibugTransfer.Config.csproj" />
<ProjectReference Include="..\AxibugTransfer.Tcp\AxibugTransfer.Tcp.csproj" />
</ItemGroup>

14
AxibugTransfer/Program.cs Normal file
View File

@ -0,0 +1,14 @@
using AxibugTransfer.Tcp;
using AxibugTransfer.Config;
if (!Config.LoadConfig(out List<CfgInfo> cfgList))
{
Console.WriteLine("请检查配置文件!");
return;
}
foreach (CfgInfo cfg in cfgList)
new TcpTransfer(cfg.localPort, cfg.targetIP, cfg.targetPort, true).Start();
while (true)
Console.ReadLine();

View File

@ -0,0 +1 @@
80:127.0.0.1:8080

View File

@ -1,3 +1,29 @@
# AxibugTransfer
一个自封装的端口转发类库
一个自制的开源端口转发工具 By 皓月
dotNet 版本: .Net 6
平台: Windows/Linux/Other..
项目"AxibugTransfer"为控制台版本项目
项目"AxibugTransfer.Tcp"为TCP端口转发库
##控制台版本使用方法
下载Release版本或者自编译AxibugTransfer项目.
编辑可执行程序目录的config.cfg配置文件
格式(可多行)
本地监听端口:目标IP:目标端口
如:
80:1.2.3.4:8080
81:1.2.3.4:8081
标识
将本地80端口TCP/HTTP请求转发到1.2.3.4的8080端口上
将本地81端口 转发到1.2.3.4的8081端口上
TODO:
完善的统计功能
使用 IOCP/epoll 提升性能
也许做一个GUI版本