Monday, November 26, 2012

iphone下面通过bash script 自动添加被墙网站到pac文件

最近研究pac文件疯了,我iphone里面有一个autoproxy2pac项目生成的pac文件

这个文件是基于gfwlist的,gfwlist也会有漏网之鱼,所以有时候需要手动添加

但是在iphone下面用ifile编辑这个pac文件是非常痛苦的事情,所以我研究是不是有bash script能更好的帮助我更新这个pac文件

研究结果出来了,完全可行,感谢 irc.freenode.net  #bash 频道的三位国外大神的帮助

首先几个前提:
1 我已经有一个基础的 pac文件位于 /var/root/ap , 且权限为 777,所有者和组为 mobile,所有手动添加的被墙网站我都会放在文件里面一句 //added by hand 下面。(注意下面的脚本用到了这句话,以确保加入到pac的代码能在合适的位置)
2 说到bash,那肯定是要在命令行下面执行的,所以需要ssh进入iphone
3 这个script需要用到ed,所以安装ed,用 apt-get ed


脚本内容:

#!/bin/bash
domain=${1//./\\.}
ed -s /var/root/ap << EOF
/\/\/added by hand/a
if(/\.${domain}/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?${domain}/i.test(url)) return PROXY;
if(/^https?:\/\/[^\/]+${domain}/i.test(url)) return PROXY;
.
w
EOF


将以上内容保存到 /usr/bin/upac
并运行 chmod +x /usr/bin/upac

以后要添加被墙网站到pac 就直接终端运行:

upac twitter.com
upac google.com
upac google.com.hk
upac bit.ly

等等等等!!!

我的PAC文件,有兴趣可以以此为基础添加今后可能会被墙的网站

https://www.dropbox.com/s/u6u6rsy5m22jf8u/ap

update:
已经有更简洁的方式了,不需要依赖任何gfwlist 见:
http://catty-house.blogspot.com/2012/11/iphonevpspythonpac.html






Thursday, November 22, 2012

windows 7 wifi 热点

目的:

将windows 7 PC的有线连接共享给无线网卡,同时让无线网卡作为AP,供iPhone使用。

方法:

以下命令逐条执行(需administrators组权限):
netsh wlan set hostednetwork mode=allow
netsh wlan set hostednetwork ssid=yourssid key=yourpasswd keyUsage=persistent
netsh wlan start hostednetwork
此时 位于 Control Panel\Network and Internet\Network Connections 会出现一个:
Wireless Network Connection 2

然后到 Local Area Connection 属性界面,开启共享,共享给 Wireless Network Connection 2

用iPhone连接此无线即可上网。

Sunday, July 29, 2012

script that automatically mount flash disk and execute commands on plugged in (插入优盘自动挂载并执行命令)

Tags: udev, UUID.

1 Find out unique ID of the flash disk for udev :
$ udevadm info -a -p  $(udevadm info -q path -n /dev/sdc) |grep  serial
Here is the output:
serialATTRS{serial}=="2004290613079860C679"
(change /dev/sdc for your condition)

2 create udev rules
$ sudo vim /etc/udev/rules.d/81-sandisk.rules
Put the following in this file :
KERNEL=="sd*", ATTRS{serial}=="2004290613079860C679", SYMLINK+="sandisk", RUN+="/bin/bash /home/j/script/sandisk.sh"

3 Find out the unique ID of the flash disk for linux filesystem
ls /dev/disk/by-uuid/
Here is one of the output:
48DD-2448 -> ../../sdc1

4 Create a script
$ cd ~/script/ (note this path must be in $PATH)
$ vim sandisk.sh
Put the following into the script:
#!/bin/bash
device=`ls /dev/disk/by-uuid/48DD-2448 -l | awk -F/ '{print $NF}'`  #assign a variable to $device, because the location of flash disk changes often, sometimes /dev/sdb, sometimes /dev/sdc...
sudo mount -t vfat /dev/$device /mnt/sandisk/ # mount the flash disk
# add your stuff below, ie, tar /etc/ ~/ and mv to the flash disk
# script END
4.1 $ sudo chmod +x sandisk.sh

5 Point:
5.1 what? mount and execute commands as flash disk be blugged in
5.2 why? udev and filesystem both has it's unique id for a special disk, that makes sense
5.3 connection between UUID and udev is possible :)
5.4 this script will work only on THE flash disk, because udev attrs serial and uuid are UNIQUE

Have Fun!

Source:
1 udev
2 uuid



Saturday, July 21, 2012

Awesome Gentoo

Awesome Gentoo!
it's super fast! stable! cute!
with firefox, google chrome, fluxbox, openbox installed
only 4GB for normal usage!