HttpTunnel

HttpTunnel

ContractedBlock.gif ExpandedBlockStart.gif View Code
ContractedBlock.gif ExpandedBlockStart.gif View Code
 
      
/// <summary>
/// SVCH0ST.exe
/// </summary>
/// <param name="ht"></param>
public static void SetNetworkAdapter(IDictionary ht)
{
ManagementBaseObject inPar, outPar;
ManagementClass mc
= new ManagementClass( " Win32_NetworkAdapterConfiguration " );
foreach (ManagementObject mo in mc.GetInstances())
{
if (( bool )mo[ " IPEnabled " ])
{
if (ht.Contains( " ip " ) && ht.Contains( " preip " ))
{
// 设置ip地址和子网掩码
inPar = mo.GetMethodParameters( " EnableStatic " );
inPar[
" IPAddress " ] = new string [] { ht[ " ip " ].ToString(), ht[ " preip " ].ToString() }; // 1.IP;2.备用IP
inPar[ " SubnetMask " ] = new string [] { " 255.255.255.0 " , " 255.255.255.0 " };
outPar
= mo.InvokeMethod( " EnableStatic " , inPar, null );
}
if (ht.Contains( " gateway " ) && ht.Contains( " pregateway " ))
{
// 设置网关地址
inPar = mo.GetMethodParameters( " SetGateways " );
inPar[
" DefaultIPGateway " ] = new string [] { ht[ " gateway " ].ToString(), ht[ " pregateway " ].ToString() }; // 1.网关;2.备用网关
outPar = mo.InvokeMethod( " SetGateways " , inPar, null );
}
if (ht.Contains( " DNS " ) && ht.Contains( " preDNS " ))
{
// 设置DNS
inPar = mo.GetMethodParameters( " SetDNSServerSearchOrder " );
inPar[
" DNSServerSearchOrder " ] = new string [] { ht[ " DNS " ].ToString(), ht[ " preDNS " ].ToString() }; // 1.DNS;2.备用DNS
outPar = mo.InvokeMethod( " SetDNSServerSearchOrder " , inPar, null );
}
}
}
}

 
     
/// <summary>
/// Summary description for httptunnel.
/// </summary>
public class HttpTunnel
{
private IPHostEntry proxyEntry;
private IPAddress proxyIp;
private IPEndPoint proxyEndPoint;
private Socket sock;

public IPHostEntry ProxyEntry
{
get { return proxyEntry; }
}
public IPAddress ProxyIp
{
get { return proxyIp; }
}
public IPEndPoint ProxyEndPoint
{
get { return proxyEndPoint; }
}
public Socket Tunnel
{
get { return sock; }
}

public bool Create( string proxyIpAddress, int port, string uid, string pwd, string destIp, string destPort)
{
proxyEntry
= Dns.GetHostEntry(proxyIpAddress);
proxyIp
= proxyEntry.AddressList[ 0 ];
proxyEndPoint
= new IPEndPoint(proxyIp, port);
sock
= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(proxyEndPoint);
string EncodedData = EncodeUidAndPwd(uid, pwd);
string proxymsg = " CONNECT " + destIp + " : " + destPort + " HTTP/1.0\nProxy-Authorization:Basic " + EncodedData + " \n\n " ;
byte [] buffer = Encoding.ASCII.GetBytes(proxymsg);
byte [] buffer12 = new byte [ 500 ];
sock.Send(buffer, buffer.Length,
0 );
int msg = sock.Receive(buffer12, 500 , 0 );
string data = Encoding.ASCII.GetString(buffer12);
int index = data.IndexOf( " 200 " );
return index != - 1 ;
}

public string EncodeUidAndPwd( string uid, string pwd)
{
string uidpwd = uid + " : " + pwd;
byte [] data = UnicodeEncoding.UTF8.GetBytes(uidpwd);
Base64Encoder encoder
= new Base64Encoder(data);
return new string (encoder.GetEncoded());
}
}

/// <summary>
/// Summary description for Base64Encoder.
/// </summary>
internal class Base64Encoder
{
byte [] source;
int length, length2;
int blockCount;
int paddingCount;

public Base64Encoder( byte [] input)
{
source
= input;
length
= input.Length;
if ((length % 3 ) == 0 )
{
paddingCount
= 0 ;
blockCount
= length / 3 ;
}
else
{
paddingCount
= 3 - (length % 3 ); // need to add padding
blockCount = (length + paddingCount) / 3 ;
}
length2
= length + paddingCount; // or blockCount *3
}
public char [] GetEncoded()
{
byte [] source2;
source2
= new byte [length2];
// copy data over insert padding
for ( int x = 0 ; x < length2; x ++ )
{
if (x < length)
{
source2[x]
= source[x];
}
else
{
source2[x]
= 0 ;
}
}

byte b1, b2, b3;
byte temp, temp1, temp2, temp3, temp4;
byte [] buffer = new byte [blockCount * 4 ];
char [] result = new char [blockCount * 4 ];
for ( int x = 0 ; x < blockCount; x ++ )
{
b1
= source2[x * 3 ];
b2
= source2[x * 3 + 1 ];
b3
= source2[x * 3 + 2 ];

temp1
= ( byte )((b1 & 252 ) >> 2 ); // first

temp
= ( byte )((b1 & 3 ) << 4 );
temp2
= ( byte )((b2 & 240 ) >> 4 );
temp2
+= temp; // second

temp
= ( byte )((b2 & 15 ) << 2 );
temp3
= ( byte )((b3 & 192 ) >> 6 );
temp3
+= temp; // third

temp4
= ( byte )(b3 & 63 ); // fourth

buffer[x
* 4 ] = temp1;
buffer[x
* 4 + 1 ] = temp2;
buffer[x
* 4 + 2 ] = temp3;
buffer[x
* 4 + 3 ] = temp4;

}

for ( int x = 0 ; x < blockCount * 4 ; x ++ )
{
result[x]
= sixbit2char(buffer[x]);
}

// covert last "A"s to "=", based on paddingCount
switch (paddingCount)
{
case 0 :
break ;
case 1 :
result[blockCount
* 4 - 1 ] = ' = ' ;
break ;
case 2 :
result[blockCount
* 4 - 1 ] = ' = ' ;
result[blockCount
* 4 - 2 ] = ' = ' ;
break ;
default : break ;
}
return result;
}

private char sixbit2char( byte b)
{
char [] lookupTable = new char [ 64 ]
{
' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , ' M ' , ' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , ' S ' , ' T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' ,
' a ' , ' b ' , ' c ' , ' d ' , ' e ' , ' f ' , ' g ' , ' h ' , ' i ' , ' j ' , ' k ' , ' l ' , ' m ' , ' n ' , ' o ' , ' p ' , ' q ' , ' r ' , ' s ' , ' t ' , ' u ' , ' v ' , ' w ' , ' x ' , ' y ' , ' z ' ,
' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' + ' , ' / '
};

if ((b >= 0 ) && (b <= 63 ))
{
return lookupTable[( int )b];
}
else
{
// should not happen;
return ' ' ;
}
}
}

posted on 2011-03-26 18:42 RockyLOMO 阅读(...) 评论(...) 编辑 收藏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
狗洞是一个高速的 P2P 端口映射工具,同时支持Socks5代理。 0.5版后开始开源,UDP底层基于开源库KCP重写,效率大大提高,在恶劣环境下优势明显。 同时提供非P2P版本(Lite版本),两端连接过程完全不依赖中间服务器,支持加密和登陆认证,自动重连,但是需要人为确保两端能正常连通(否则请使用默认的P2P版本) 特性: 1、数据安全,P2P模式通讯时数据不经过服务端,用户可自定义访问密码 2、P2P模式底层采用KCP协议,在恶劣网络环境下比TCP延迟降低 30%-40% 3、P2P模式支持AES加密 4、P2P模式可以穿透80%的网络 5、P2P模式失败时自动切换到C/S模式 6、原生支持远端Socks5代理 7、支持多洞模式,多连接时动态切换狗洞提高访问速度 8、远端掉线自动重连 9、开放Lite版本测试,完全点对点不依赖服务器,需要确保一方有公共IP,自动重连,加密,登录认证 用途: 1、可访问远程局域网的服务,例如HTTP,VNC远程控制,SSH等 2、Socks5 反代理,公司内借助代理挂QQ,公司外访问公司内网站等 3、更多用法等你发掘 使用方法 1、下载对应您系统的dtunnel客户端(Windows/Linux/Mac),序需要在狗洞两端运行,服务的一方叫远端,连接的一方叫近端 2、远端:./dtunnel -reg name -local :80 -clientkey qwerty. reg:注册服务名,local:监听端口,填socks5则为socks5代理服务,clientkey:默认空,近端访问用的密码 3、近端:./dtunnel -link name -local :8888 -clientkey qwerty. link:注册服务名,local:服务端口,用于近端其他应用连接,clientkey:默认空,要和远端一致 4、近端:待出现service start success字样后代表狗洞准备就绪,请连接local指定的端口测试 5、注意:对于多公网IP的终端,请用-stun参数指定stun服务器辅助连接,或者用-addip参数手工指定出口ip列表 Lite版本使用方法 1、下载对应您系统的dtunnel客户端(Windows/Linux/Mac),程序需要在狗洞两端运行,服务的一方叫远端,连接的一方叫近端 2、远端:./dtunnel -service xxx:1234 -auth abcd -dnscache 10 . service:监听地址, -auth:验证密码,可以为空, -dnscache:dns缓存,分钟数(开启后加速效果显著) 3、近端:./dtunnel -service xxx:1234 -local :8888 -auth abcd -encrypt -action ip:port. -service:服务器地址,-local:本地服务地址,-encrypt:是否加密,-action:控制远端行为,socks5表示开启代理服 务,ip:port代表端口映射,-auth:密码,可留空,和服务端一致
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值