锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
0.鍙湁涓涓枃浠?br />
CC = gcc
CCFLAGS = -O2 -s
BIN = test
OBJ = root_password_tool_win32.o
$(BIN) : $(OBJ)
$(CC) $(CCFLAGS) -o test $(OBJ)
$(OBJ) : root_password_tool_win32.c
$(CC) $(CCFLAGS) -c root_password_tool_win32.c
.PHONY : clean
clean :
-rm $(BIN) $(OBJ)
1.綆鍗曠紪璇戝懡浠よ紼嬪簭錛?(CC)鍓嶉潰鏄痶ab錛屼笉鏄痵pace
涓鍏變簲涓枃浠訛細(xì)
test.c
md5.c md5.h
password.c password.h
main鍑芥暟鍦╰est.c涓紝test.c鏂囦歡include浜?jiǎn)md5.h鍜宲assword.h
CCFLAGS = -O2 -s
BIN = password
OBJ = md5.o password.o test.o
$(BIN) : $(OBJ)
$(CC) $(CCFLAGS) -o password $(OBJ)
md5.o : md5.c md5.h
$(CC) $(CCFLAGS) -c md5.c
password.o : password.c password.h
$(CC) $(CCFLAGS) -c password.c
test.o : test.c
$(CC) $(CCFLAGS) -c test.c
.PHONY : clean
clean :
-rm $(BIN) $(OBJ)
make # 緙栬瘧寰楀埌password.exe錛岃繖閲屽湪windows涓媍igwin+mingw鐜涓紪璇?br />make clean # 娓呯悊緙栬瘧鐢熸垚鐨?.o絳夋枃浠?br />
2.浣跨敤g++緙栬瘧win32紼嬪簭鐨凪akefile錛屽叾涓畝鍐欎簡(jiǎn)涓浜涳紝鍙互瀵規(guī)瘮1鐪嬬湅涓嶅悓涔嬪
璇存槑錛?br /> (0)鎸囧畾闈?rùn)鎬佸簱鐩綍錛岃繛鎺ラ潤(rùn)鎬佸簱libcomctl32.a緙栬瘧紼嬪簭
(1)緙栬瘧windows璧勬簮鏂囦歡(浣跨敤mingw鐨剋indres)
(2)浣跨敤-mwindows緙栬瘧閫夐」鍘婚櫎寮瑰嚭鐨刢md紿楀彛
# -O2 : optimization option
# -s : build small binary
# -mwindows : use this option to remove the popping cmd window
CCFLAGS = -O2 -s -mwindows
BIN = test
WINDRES = windres
RES = resource.o
OBJ = main.o md5.o password.o $(RES)
# where is your mingw library?
LIBPATH = 'C:\Program Files\CodeBlocks\MinGW\lib\'
LIBS=-L$(LIBPATH) -lcomctl32
RM = -rm
$(BIN): $(OBJ)
$(CC) $(CCFLAGS) -o $(BIN) $(OBJ) $(LIBS)
main.o: main.cpp
md5.o: md5.cpp md5.h
password.o: password.cpp password.h
# 緙栬瘧璧勬簮鏂囦歡
$(RES): resource.rc rpt.ico manifest
$(WINDRES) -o $(RES) resource.rc
.PHONY:clean
clean:
$(RM) $(BIN) $(OBJ)
3.緙栬瘧闈?rùn)鎬佸簱
鍏朵腑涓浜?<錛?^, $@鏄疢akefile鐨勮嚜鍔ㄥ寲鍙橀噺錛岃緇嗕簡(jiǎn)瑙e彲浠ョ湅銆婅窡鎴戜竴璧峰啓Makefile銆嬬殑絎簲绔?br />
# -g : for debug
CFLAGS = -g -O2 -Wall -DPOSIX
TARGET = libutp.a
.cpp.o:
$(CC) -c $(CFLAGS) $<
all: $(TARGET)
libutp.a: $(OBJS)
ar cru $@ $^
ranlib $@
.PHONY : clean
clean :
-rm *.o $(TARGET)
(0)windows涓嬩嬌鐢╩ingw緙栬瘧dll鍔ㄦ佸簱
OBJS = utp.o utp_utils.o
CCFLAGS = -fno-exceptions -fno-rtti -Wall -g -lwsock
TARGET = libutp.dll
all: $(TARGET)
$(TARGET): $(OBJS)
-rm -f $(TARGET)
$(CC) -shared -o $(TARGET) $(OBJS) -lws2_32
.cpp.o:
$(CC) -c -DPOSIX -fpic -I . -I utp_config_lib $(CCFLAGS) $<
.PHONY: clean
clean:
-rm -f $(OBJS) $(TARGET)
(1)linux涓嬬紪璇憇o鍔ㄦ佸簱
OBJS = utp.o utp_utils.o
CCFLAGS = -fno-exceptions -fno-rtti -Wall -g
TARGET = libutp.so
all: $(TARGET)
$(TARGET): $(OBJS)
-rm -f $(TARGET)
g++ -shared -o $(TARGET) $(OBJS)
.cpp.o:
g++ -c -DPOSIX -fpic -I . -I utp_config_lib $(CCFLAGS) $<
.PHONY: clean
clean:
-rm -f $(OBJS) CCFLAGS
5.緙栬瘧澶氫釜鐩爣錛?-2鍧囨槸緙栬瘧鍗曚釜鐩爣
(0) 娣誨姞澶存枃浠剁洰褰?br />(1) 浣跨敤鑷繁緙栬瘧鐨勯潤(rùn)鎬佸簱libutp.a
CFLAGS = -g
LIBUTP_PATH = /home/actiontec/workspace/code_reading/third_party/libutp/lib
INCLUDES = -I${LIBUTP_PATH}
LIBS = -L$(LIBUTP_PATH) -lutp -lpthread -lrt
TARGET = all
all: server client
server: server.cpp
$(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) $(LIBS)
client: client.cpp
$(CC) $(CFLAGS) -o $@ $^ $(INCLUDES) $(LIBS)
.PHONY : clean
clean:
-rm *.o server client
]]>
PC A: Ubuntu 12.04 LTS錛屼袱鍧楃綉鍗★紝鍒嗗埆涓篹th0鍜宔th1錛屼嬌鐢╡th0榪炴帴
PC B: Windows 7, 涓鍧楃綉鍗★紝涓篹th0
鐩爣錛?u>
浣垮緱B閫氳繃A榪炴帴浜掕仈緗?IPv4)錛屽嵆瀹炵幇A涓鴻礬鐢卞櫒鐨勫姛鑳?u>
姝ラ錛?u>
PC A:
(0)鍋囪eth0宸茬粡閰嶇疆濂斤紝PC鍙互閫氳繃eth0榪炴帴浜掕仈緗?wbr>錛岄厤緗甧th1涓猴紝濡?etc/network/
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 172.16.10.65
gateway 172.16.10.254
netmask 255.255.0.0
auto eth1
iface eth1 inet static
address 192.168.6.1
netmask 255.255.255.0
network 192.168.6.0
broadcast 192.168.6.255
褰撶劧錛屾垜鏄垹闄や簡(jiǎn)network-manager,
浣犱篃鍙互閫氳繃network-manager鏉ラ厤緗侱NS鏈嶅姟
nameserver 168.95.1.1 #榪欐槸鎴戠殑DNS鏈嶅姟鍣紝浣犲彲浠ラ厤緗垚浣犲彲浠ヨ闂殑錛屽8.8.
閲嶅惎浣犵殑緗戠粶鏈嶅姟鎴栬呴噸鍚疨C A錛屼互涓婅緗氨鍙互鐢熸晥銆?u>
(1)Linux緋葷粺鑷韓灝辨湁IPv4鍖呰漿鍙戠殑鍔熻兘錛屽湪/
鎵撳紑IPv4杞彂鍔熻兘:
net.ipv4.ip_forward=1
杈撳叆浠ヤ笅鍛戒護(hù)浣垮緱涓婇潰鐨勮緗敓鏁?鎴栬呴噸鍚數(shù)鑴?錛?u>
sudo sysctl -p
(2)閫氳繃iptable瀹炵幇IPv4鍖呰漿鍙?u>
sudo iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -o eth0 -j MASQUERADE
鍙互閫氳繃iptables-save灝唅ptables rule閮戒繚瀛樺埌鏂囦歡涓紝鍦ㄩ氳繃iptables-
鍙互鑷繁鍐欎竴涓剼鏈潵瀹炵幇iptables鑷姩鐨勮澆鍏ule錛?wbr>鎴栬呮壘鍒癷ptables鐨勯厤緗枃浠舵潵淇敼
PC B
(0)灝哖C B鐨別th0涓嶱C A鐨別th1鐢ㄧ綉綰跨洿鎺ヨ繛鎺ワ紝閰嶇疆PC B鐨別th0涓猴細(xì)
IP ADDRESS : 192.168.6.101
SUBNET MASK: 255.255.255.0
GATE WAY : 192.168.1.1i
DNS Server : 168.95.1.1
榪欐牱PC B灝卞彲浠ラ氳繃PC A榪炴帴浜掕仈緗戜簡(jiǎn)
澧炲己閰嶇疆錛?u>
璺敱鍣ㄩ兘鍙互鑷姩緇橮C鍒嗛厤IP錛岃屼笉闇瑕佹墜鍔ㄩ厤緗甀P錛?wbr>榪欐槸閫氳繃DHCP鏉ュ疄鐜扮殑銆傚鏋滀篃瑕佸疄鐜扮浉鍚岀殑鍔熻兘錛岄偅
灝遍渶瑕佸湪PC A涓婃惌寤轟竴涓狣HCP鏈嶅姟鍣ㄣ?u>
(0)瀹夎DHCP鏈嶅姟鍣?u>
sudo apt-get install isc-dhcp-common isc-dhcp-server
(1)閰嶇疆DHCP
(i)淇敼/etc/default/isc-dhcp-
INTERFACES="eth1"
(ii)淇敼/etc/dhcp/dhcpd.conf
subnet 192.168.6.0 netmask 255.255.255.0 {
range 192.168.6.100 192.168.6.200;
option routers 192.168.6.1;
option broadcast-address 192.168.6.255;
option domain-name-servers 168.95.1.1;
default-lease-time 600;
max-lease-time 7200;
}
(2)PC B鍙互鑷姩鑾峰彇IP浜?jiǎn)锛屽鏋滃湪PC A鐨別th1涓婃帴涓涓猻witch錛屾帴鍦╯witch涓婃墍鏈夌殑P
]]>
浠ヤ笅閮芥槸鍦╱buntu涓嬭繘琛岀殑
鍙傝?br />
http://www.libfetion.cn/Docs-dve/Build-LibFx-on-ubuntu.txt
璇蜂嬌鐢╯vn瀹㈡埛绔笅杞絣ibfetion-gui鐨勬簮鐮?br />
http://libfetion-gui.googlecode.com/svn/
瀹夎寮鍙戣繃紼嬩腑闇瑕佺殑杞歡
2 sudo apt-get install g++
3 sudo apt-get install libcurl4-openssl-dev
鍦╰runk/qt4_src/libfetion/lib鐩綍涓嬫壘鍒伴潤(rùn)鎬佸簱libfetion_32.a錛岀敱浜庝唬鐮佹墦綆楁槸鐢╬ython鏉ュ啓錛屾墍浠ュ埗浣滀簡(jiǎn)涓涓姩鎬佸簱libfetion.so
鍏蜂綋姝ラ濡備笅錛?br />
ar -x libfetion_32.a
#閲嶆柊灝佽涓簊o
g++ -shared -Wall -fPIC -lcurl -pthread *.o -o libfetion.so
#鏌ョ湅so[鍙夋楠
nm libfetion.so
鍙戦佸ぉ姘旈鎶ョ殑python浠g爜濡備笅錛宭ibfetion.so涓叿浣撶殑鏂規(guī)硶璇鋒煡鐪媡runk/qt4_src/libfetion/include/libfetion/libfetion.h
2 #coding=utf-8
3 #only can run at linux
4 import os
5 import ctypes
6 import urllib2
7
8 #鍩庡競(jìng)浠g爜鍒楄〃
9 city_codes = {
10 '鍚堣偉' : 'CHXX0448',
11 '瀹夊簡(jiǎn)' : 'CHXX0452',
12 '澶╂觸' : 'CHXX0133',
13 '鍗楁槍' : 'CHXX0097',
14 '涓婃搗' : 'CHXX0097',
15 '鍖椾含' : 'CHXX0097',
16 '闀挎矙' : 'CHXX0013',
17 '甯稿痙' : 'CHXX0416',
18 '鍖椾含' : 'CHXX0008',
19 '閾跺窛' : 'CHXX0259'
20 }
21
22 #鐢ㄦ埛瀹氬埗鍩庡競(jìng)
23 weather_users = {
24 '澶╂觸':['138*******3','159*******7','159*******2','150*******6','135*******1'],
25 '鍖椾含':['159*******2'],
26 '閾跺窛':['159*******2']
27 }
28
29 #鑷繁鎵嬫満
30 myself_city_list = ['澶╂觸','瀹夊簡(jiǎn)']
31
32 class weather:
33 weatherBaseUrl = "http://www.thinkpage.cn/weather/weather.aspx?uid=&l=zh-CN&p=CMA&a=0&u=C&s=4&m=0&x=1&d=2&fc=&bgc=&bc=&ti=1&in=1&li=2&c="
34 #鍒濆鍖?/span>
35 def __init__(self):
36 pass
37
38 #娓呯┖html
39 def clear_html(self):
40 cmd = 'rm -f *.htm'
41 os.popen(cmd)
42
43 #鑾峰緱闇瑕佸彂閫佺殑鍩庡競(jìng)浠g爜
44 def __getCityToSend(self):
45 self.city_all = {}
46 for key in weather_users.keys():
47 self.city_all[key] = 1
48 for key in myself_city_list:
49 self.city_all[key] = 1
50
51 #鑾峰彇html
52 def get_html(self):
53 self.__getCityToSend();
54 for key in self.city_all.keys():
55 weatherUrl = self.weatherBaseUrl + city_codes[key]
56 req = urllib2.Request(weatherUrl)
57 res = urllib2.urlopen(req)
58 weather_content = res.read()
59 res.close()
60 file_html = open(city_codes[key] + '.htm','w')
61 file_html.write(weather_content)
62 file_html.close()
63
64 #榪囨護(hù)鏃犵敤淇℃伅
65 def parse_html(self):
66 for key in self.city_all.keys():
67 file_name = city_codes[key] + '.htm'
68
69 #鑾峰緱淇℃伅鎵鍦ㄨ
70 cmd = 'cat %s.htm |grep -E \'ltl|forecastDay|temp\'|grep -v spanDate > %s.htm' % (city_codes[key],city_codes[key])
71 os.popen(cmd)
72
73 #鍘繪帀html浠g爜
74 cmd = 'sed -i -e \'s/<[^>]*>//g\' %s.htm' % city_codes[key]
75 os.popen(cmd)
76
77 #鍘繪帀涓嶇浉鍏沖瓧絎?/span>
78 cmd = 'sed -i -e \'s/°/°/g;s/ //g\' %s.htm' % city_codes[key]
79 os.popen(cmd)
80
81 #鏍規(guī)嵁鍩庡競(jìng)鐢熸垚娑堟伅
82 def __generate_msg(self,city_key):
83 #鎵撳紑鏂囦歡
84 file_html = open(city_codes[city_key] + '.htm')
85
86 #璇誨彇淇℃伅
87 weather_lines = file_html.readlines()
88 file_html.close()
89 weather_content = ''
90 for line in weather_lines:
91 weather_content = weather_content + line.replace('\r\n',' ')
92 return weather_content
93
94 #鐧誨綍椋炰俊
95 def fetion_login(self, your_mobile_no, your_pwd):
96 self.libc = ctypes.cdll.LoadLibrary('/home/loh/weather/libfetion.so')
97 self.libc.fx_init()
98 self.libc.fs_login(your_mobile_no,your_pwd)
99 self.libc.fx_set_longsms(True)
100
101 #閫鍑洪淇?nbsp;
102 def fetion_logout(self):
103 self.libc.fx_loginout()
104 self.libc.fx_terminate()
105
106 #緇欒嚜宸卞彂淇℃伅
107 def send_msg_to_myself(self):
108 for city_key in myself_city_list:
109 msg = self.__generate_msg(city_key)
110 self.libc.fs_send_sms_to_self(msg)
111
112 #緇欑敤鎴峰彂淇℃伅
113 def send_msg(self):
114 for city_key in weather_users.keys():
115 msg = self.__generate_msg(city_key)
116 for user in weather_users[city_key]:
117 self.libc.fs_send_sms_by_mobile_no(user,msg)
118
119 #緇欑敤鎴峰彂閫佹榪庝俊鎭?/span>
120 def send_welcome_msg(self, msg):
121 user_all = {}
122 for user_list in weather_users.values():
123 for user in user_list:
124 user_all[user] = 1
125
126 for user in user_all.keys():
127 self.libc.fs_send_sms_by_mobile_no(user,msg)
128
129
130 if __name__ == '__main__':
131 weather = weather()
132 weather.get_html()
133 weather.parse_html()
134 weather.fetion_login('136*******3', 'password')
135 weather.send_msg_to_myself()
136 weather.send_msg()
137 #weather.send_welcome_msg('鎮(zhèn)ㄥソ錛佸ぉ姘旈鎶ュ叏綰垮崌綰э紝鏀寔鍥藉唴鎵鏈夊煄甯?jìng)浠ュ強(qiáng)鍥藉涓昏澶у煄甯?jìng)錛屾澶栨?zhèn)q樺彲浠ュ畾鍒跺涓煄甯?)
138 weather.fetion_logout()
139 weather.clear_html()
緙栧啓鑴氭湰鍜屼換鍔¤鍒?br />
緙栧啓鑴氭湰錛?br />
vim weather
鍐欏叆浠ヤ笅鍐呭
2 python weather.py
浠誨姟璁″垝錛?br />
crontab -e
鍐欏叆浠ヤ笅鍐呭錛堟瘡澶╂棭涓?鐐?鍒嗘墽琛岃剼鏈級(jí)
2 1 7 * * * /home/loh/weather/weather
澶╂皵棰勬姤鍐呭鏄繖鏍風(fēng)殑錛?br />
]]>