点击在新窗口中浏览此图片

原图地址:http://linux-ip.net/nf/nfk-traversal.png
【阿权的第一篇翻译/aslibra.com】
这是Linux/Ubuntu下的Freecap

如果你想通过socks5代理服务器透明的转发所有的TCP流量,那下面就是你需要的 :)
(特别对于linux的wow游戏者,这个特别方便)

你需要先在linux系统安装一些东西。大部分通过apt就可以,另外还需要下载一个文件。
打开命令行,然后敲打下面的命令:

cd
sudo apt-get install iptables git-core libevent-1.4-2 libevent-dev
git clone http://github.com/darkk/redsocks.git
cd redsocks/
make
echo 'base{log_debug = on; log_info = on; log = "file:/tmp/reddi.log";
       daemon = on; redirector = iptables;}
       redsocks { local_ip = 127.0.0.1; local_port = 31338; ip = 127.0.0.1;
       port = 31337; type = socks5; }' > redsocks.conf
./redsocks -c redsocks.conf


现在保证你的socks5代理服务器是正常运行的。如果你是用wowtunnels.com,那你可以用你的账号通过SSH连接上。或者你有另外一个linux服务器,可以用ssh登录。又或者,你有一个现成的socks5服务器也可以。
下面是一个命令的例子,本地监听31337端口:
ssh -fqND 31337 yourusername@tunnel4.wowtunnels.com


那现在用iptables通过我们的redsocks转换器转发所有流量,复制下面的命令,粘贴到命令行就可以:

sudo iptables -t nat -N REDSOCKS
sudo iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
sudo iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN
sudo iptables -t nat -A REDSOCKS -p tcp -o eth0 -j DNAT --to 127.0.0.1:31338
sudo iptables -t nat -A OUTPUT -p tcp -j REDSOCKS


但是,我们不希望转发那些连接我们的代理服务器的流量,所以我们需要找到它的ip,添加一个例外:

ping tunnel4.wowtunnels.com    
(这可以知道socks5服务器的ip,比如是67.220.203.130)


那就执行如下命令:
sudo iptables -t nat -I REDSOCKS -d 67.220.203.130 -j RETURN


喔~ 所有流量都透明地通过redsocks映射到socks5服务器啦~ 不需要调整任何的程序配置!
本例子2010-07-19在 ubuntu10.04 测试通过。

关闭此代理模式,可以输入以下命令:
sudo iptables -F
sudo iptables -X
sudo iptables -Z
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t nat -Z
killall redsocks


还有问题?可以配置firefox连接socks5代理(本地的31337端口)去检查代理服务器是否正常。
就我所知,什么是对UDP/ICMP无效的。

Redirect all (TCP) traffic through transparent socks5 proxy in Linux
一提到redsocks和代理这些关键词,大家都会联想到这是翻WALL用的。
虽然redsocks是为翻WALL而生,但是我们还可以用它来连接固定的socks5代理,让内网用户通过openwrt访问外网

我的网络环境是这样的,通过pppoe拨号的方式获得内网IP,没有访问外网的权限,很苦逼,但是前些天无意中发现内网里有一台socks5的代理服务器,连接这个代理之后就可以畅通无阻的访问外网了。
在windows下,可以通过pppoe拨号获得内网IP,使用Proxifier这款软件配置socks5全局代理,来获得访问外网的权限。但是手机平板就难以做到这两步。
所以我想用openwrt做路由,先pppoe拨号获得内网IP,再通过redsocks2将内网里所有设备的连接请求全部转发到指定的socks5代理服务器,这样就可以实现终端免设置访问外网了。

估计有这种需求的人不多,但是还是记录下来作为一个例子给大家参考吧(基于openwrt-x86):

1.先使用内网账号pppoe拨号获得内网IP:

2.获取适应你openwrt平台的redsocks2,这里提供一个x86的redsocks2,其他平台请自行搜索或编译:

3.配置redsocks2,配置文件在/etc/config/redsocks.conf:
base {
log_debug = off;
log_info = off;
daemon = on;
redirector= iptables;
}

redsocks {
local_ip = 192.168.1.1;
local_port = 1081;
ip = 你的socks5代理服务器地址,也可以是域名;
port = 1080;
type = socks5;
autoproxy = 0;
}


配置文件写好后,将启动redsocks的命令加入rc.local里,实现开机启动:
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

redsocks2 -c /etc/config/redsocks.conf

exit 0

4.配置iptables,网络-防火墙-自定义规则,把内网所有端口的数据全部转发到redsocks:
iptables -t nat -N REDSOCKS
iptables -t nat -A PREROUTING -i br-lan -p tcp -j REDSOCKS
iptables -t nat -A PREROUTING -i br-lan -p udp -j REDSOCKS

# Do not redirect traffic to the followign address ranges
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 10.8.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN

# Redirect all kinds of traffic

iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 1081
iptables -t nat -A REDSOCKS -p udp -j REDIRECT --to-ports 1081

通过这样的配置之后,内网所有设备的访问请求都会通过op主路由被转发到socks5代理,获得外网访问权限:

PS:还有一个没解决的问题,这样设置之后,内网其他设备的请求是可以正常转发了,但是op本身访问网络时并没有通过socks5代理转发。
由于本地发起的网络请求不通过防火墙,所以不会走prerouting,因而没有被转发。

参考页面:
http://www.right.com.cn/fo...
SimpleXMLElement Object的数据有点怪异
里面的array用循环居然读不出来的
有个方式可以:

/**
* function object2array - A simpler way to transform the result into an array
*   (requires json module).
*
* This function is part of the PHP manual.
*
* The PHP manual text and comments are covered by the Creative Commons
* Attribution 3.0 License, copyright (c) the PHP Documentation Group
*
* @author  Diego Araos, diego at klapmedia dot com
* @date    2011-02-05 04:57 UTC
* @link    http://www.php.net/manual/en/function.simplexml-load-string.php#102277
* @license http://www.php.net/license/index.php#doc-lic
* @license http://creativecommons.org/licenses/by/3.0/
* @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0>
*/
function object2array($object)
{
    return json_decode(json_encode($object), TRUE);
}


据闻xml也可以:
function xmlstring2array($string)
{
    $xml   = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);

    $array = json_decode(json_encode((array)$xml), TRUE);

    return $array;
}


摘自:http://stackoverflow.com/questions/6167279/converting-a-simplexml-object-to-an-array
utf8的数据库,存入表情符,会出错

Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F...' for column 'content'


错误的解决办法:

引用
4 byte Unicode characters aren't yet widely used, so not every application out there fully supports them. MySQL 5.5 works fine with 4 byte characters when properly configured – check if your other components can work with them as well.

Here's a few other things to check out:

Make sure all your tables' default character sets and text fields are converted to utf8mb4, in addition to setting the client & server character sets, e.g. ALTER TABLE mytable charset=utf8mb4, MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4; and so on.

If your data is already in the utf8 character set, it should convert to utf8mb4 in place without any problems. As always, back up your data before trying!

Also make sure your app layer sets its database connections' character set to utf8mb4. Double-check this is actually happening – if you're running an older version of your chosen framework's mysql client library, it may not have been compiled with utf8mb4 support and it won't set the charset properly. If not, you may have to update it or compile it yourself.

When viewing your data through the mysql client, make sure you're on a machine that can display emoji, and run a SET NAMES utf8mb4 before running any queries.

Once every level of your application can support the new characters, you should be able to use them without any corruption.


总结就是,表结构改为支持4字节的unicode,数据库连接也用这个字符集哦,证明是可行的。
如果别的地方不支持,可以考虑去掉这些字符:

引用
Since 4-byte UTF-8 sequences always start with the bytes 0xF0-0xF7, the following should work:

$str = preg_replace('/[\xF0-\xF7].../s', '', $str);
Alternatively, you could use preg_replace in UTF-8 mode but this will probably be slower:

$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
This works because 4-byte UTF-8 sequences are used for code points in the supplementary Unicode planes starting from 0x10000.


参考来源:
http://stackoverflow.com/q...
http://stackoverflow.com/q...
分页: 8/362 第一页 上页 3 4 5 6 7 8 9 10 11 12 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐