cvca / snova

Automatically exported from code.google.com/p/snova
0 stars 0 forks source link

如何从指定hosts文件中查询域名,而非通过dns(本地及远程) #455

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
最近维基百科的https被封了,dns查询出来的ip均无法加密连,�
��定ip则可以。

现在有这样一个困惑:

1、和wikipedia类似,dns查到的twitter服务器都是连不上的,所幸
smarthosts里的ip可以直连。snova这里应该是通过hosts列表得到的I
P而非远程dns查询吧?

2、以上方法用在维基百科就无效了,基于smarthosts修改了一个
hosts列表,snova却只读取其中twitter的ip,wikipedia被无视了……�
��然远程查来的IP是不能https的。

spac设置应该是无误的,请教作者如何解决这个小问题?

我猜测snova的机制是先ping远程dns查来的ip,如果超时再从hosts�
��查,能ping通就无视hosts,不知对否?(twitter的IP是完全被墙
掉的,维基则只墙https,ip能ping通)

Original issue reported on code.google.com by binkto...@gmail.com on 21 Jun 2013 at 7:56

GoogleCodeExporter commented 9 years ago
自定义IP的话,需要修改hosts下的user_hosts.conf, 
添加自定义的映射关系。

snova/gsnova有限读取hosts下的hosts(非系统),其次是DNS(包括�
��统hosts)

Original comment by yinqiwen@gmail.com on 25 Jun 2013 at 8:04

GoogleCodeExporter commented 9 years ago
要写成什么样的格式呢?比如我要
wikipedia.org
www.wikipedia.org
en.wikipedia.org
zh.wikipedia.org
都解析到208.80.152.201,我写成*.wikipedia.org=208.80.152.201,spac设��
�成direct,貌似无效,gsnova还是从远程给我一个连不了443的ip

Original comment by binkto...@gmail.com on 25 Jun 2013 at 12:00

GoogleCodeExporter commented 9 years ago
hosts可以这么些。 
spac写成什么样?日志里打印些啥?

Original comment by yinqiwen@gmail.com on 25 Jun 2013 at 12:15

GoogleCodeExporter commented 9 years ago
user_pre_spac.json 部分如下:
  {
    "Protocol" : "https",
    "Host" : ["wikipedia.org", "wikimedia.org", "wikibooks.org", "wikinews.org", "wikiquote.org", "wiktionary.org", "wikimediafoundation.org", "mediawiki.org"],
    "Proxy":["Direct", "C4"]
  },

user_hosts.conf部分如下:
*.wikipedia.org=208.80.152.201

gsnova.cong部分如下:
[Hosts]
#0:Disable 1:Only for HTTPS 2:All Protocols
Enable=1

连https://zh.wikipedia.org/ 后log如下:
2013/06/25 20:31:40 launch.go:101: =============Start gsnova 
0.22.1==============
2013/06/25 20:31:40 launch.go:52: Listen on address 0.0.0.0:48102
2013/06/25 20:31:41 launch.go:52: Listen on address 0.0.0.0:48100
2013/06/25 20:31:41 launch.go:52: Listen on address 0.0.0.0:48101
2013/06/25 20:31:42 local_hosts.go:56: Fetch remote clound 
hosts:https://snova.googlecode.com/svn/trunk/repository/cloud_hosts.conf
2013/06/25 20:31:42 spac.go:366: Generate PAC from  gfwlist 
https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
2013/06/25 20:31:42 spac.go:323: Fetch remote clound spac 
rule:https://snova.googlecode.com/svn/trunk/repository/cloud_spac.json
2013/06/25 20:31:44 forward.go:79: Found 208.80.154.225:443 for 
zh.wikipedia.org:443
2013/06/25 20:31:44 forward.go:205: Session[1]Request CONNECT 
https://zh.wikipedia.org:443
2013/06/25 20:31:45 forward.go:79: Found 208.80.154.225:443 for 
zh.wikipedia.org:443
2013/06/25 20:31:45 forward.go:79: Found 173.194.72.125:5222 for 
talk.google.com:5222
2013/06/25 20:31:45 forward.go:205: Session[4]Request CONNECT 
https://talk.google.com:5222
2013/06/25 20:31:45 forward.go:205: Session[2]Request CONNECT 
https://zh.wikipedia.org:443
2013/06/25 20:31:45 forward.go:79: Found 208.80.154.225:443 for 
zh.wikipedia.org:443
2013/06/25 20:31:46 forward.go:205: Session[5]Request CONNECT 
https://zh.wikipedia.org:443
2013/06/25 20:31:46 google.go:118: Session[6]Request GET 
http://toolbarqueries.google.com/search?client=navclient-auto&hl=en&ch=622599678
23&ie=UTF-8&oe=UTF-8&features=Rank&q=info:http://zh.wikipedia.org
2013/06/25 20:31:48 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:31:49 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:31:49 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:31:59 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:32:00 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:00 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:32:03 google.go:97: Session[7]Request CONNECT 
https://autoproxy-gfwlist.googlecode.com:443
2013/06/25 20:32:04 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:04 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:32:04 google.go:97: Session[8]Request CONNECT 
https://mail.google.com:443
2013/06/25 20:32:09 google.go:97: Session[9]Request CONNECT 
https://chatenabled.mail.google.com:443
2013/06/25 20:32:12 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:32:13 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:13 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:32:14 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:32:15 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:15 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:32:23 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:32:24 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:24 c4_http.go:147: Pull worker[*******]:0 start working
2013/06/25 20:32:25 c4_http.go:151: Pull worker[*******]:0 recv invalid 
res:<nil>
2013/06/25 20:32:26 c4_http.go:160: Pull worker[*******]:0 stop working
2013/06/25 20:32:26 c4_http.go:147: Pull worker[*******]:0 start working

Original comment by binkto...@gmail.com on 25 Jun 2013 at 12:36

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
user_pre_spac里这样写:
  {
    "Protocol" : "https",
    "Host" : ["wikipedia.org", "wikimedia.org", "wikibooks.org", "wikinews.org", "wikiquote.org", "wiktionary.org", "wikimediafoundation.org", "mediawiki.org"],
    "Proxy":["Direct", "C4"]
  }, 

user_host.conf 就按照上面那样写
*.wikipedia.org=208.80.152.201

gsnova.conf设置的是
[Hosts]
#0:Disable 1:Only for HTTPS 2:All Protocols
Enable=1

连接维基百科得到log如下

Original comment by binkto...@gmail.com on 25 Jun 2013 at 12:42

Attachments:

GoogleCodeExporter commented 9 years ago
同理我这样设置twitter,根据反复测试,gsnova应该是按照下面�
��个流程
1、远程查询twitter的ip
2、得到的所有ip都连不上(没办法,twitter墙得最彻底)
3、大概几秒之后,gsnova从本地按照user_hosts、cloud_hosts、smartho
sts的顺序查到一个可用ip
4、顺利连通

这里少了一层判断,判断一个ip是否可用还要看是否https连的�
��就像维基的ip,dns得到的208.80.154.225能连上80端口了,gsnova就
把它丢缓存里了,结果443被gfw干掉了……

最好还是能允许优先本地host查询,就像以前0.17版可以设置pre
ferDNS=false这样的功能,对付这种封特定ip或者特定端口的比较
有效

Original comment by binkto...@gmail.com on 25 Jun 2013 at 1:18

GoogleCodeExporter commented 9 years ago
这个是hosts优先

Original comment by yinqiwen@gmail.com on 25 Jun 2013 at 2:42

Attachments:

GoogleCodeExporter commented 9 years ago
这个host应该写在哪里?我在cloud_hosts.conf  hosts_0.txt  
user_hosts.conf 三个文件里都写进去了,貌似都不读取的
log里面是

forward.go:136: Failed to dial address:www.wikipedia.org:443 for reason:No 
available IP found for www.wikipedia.org:443
forward.go:203: Failed to connect forward address for www.wikipedia.org:443.
dispatch.go:111: Session[1][WARN][Forwardhttp://www.wikipedia.org:443]Failed to 
request proxy event for reason:No available IP found for www.wikipedia.org:443
dispatch.go:147: Session[1]Process error:No proxy found for request 'CONNECT 
www.wikipedia.org:443' with 1 candidates for host:www.wikipedia.org:443
dispatch.go:217: Session[1]Browser close connection:Remote conn closed.

Original comment by binkto...@gmail.com on 25 Jun 2013 at 4:56

GoogleCodeExporter commented 9 years ago
放到user_hosts.conf中
208.80.152.201这个ip是连不上的

Original comment by yinqiwen@gmail.com on 26 Jun 2013 at 12:50

GoogleCodeExporter commented 9 years ago
user_hosts.conf里写了
*.wikipedia.org=208.80.152.201
www.wordpress.com=66.155.9.238
wordpress.com=66.155.11.243
这种通配符格式可以解析的吧?
事实上这个ip一直可连的,请看附件图片
0.22.2这一版新增加了两个问题:
1、完全不读取hosts_0.txt,我在smarthost基础上增加了一些可连��
�ip,但都被忽视了,包括facebook(默认的有个ExceptCloudHosts=(www
.)?facebook.com|www.chromium.org,我把它注释掉了)、twitter、wikipedi
a、wordpress等,如附件中所示,而0.22.1无此问题;并不是按照�
��想的user_hosts、cloud_hosts、hosts_0的顺序去查询,找不到再远��
�解析的机制(这种机制应该最为合理,当然google的ip不应该��
�hosts_0里找,前两个就够了)
2、判断IP是否可连的机制有问题,附件log里面出现Failed to 
request proxy event for reason:No available IP found for 
****的地方,大部分事实上即便远程通过8.8.8.8解析出来的ip都�
��可连的,可是gsnova不知道是怎么判断的,过早地就认为没有
可用ip。
麻烦作者再看看?

Original comment by binkto...@gmail.com on 26 Jun 2013 at 5:00

Attachments:

GoogleCodeExporter commented 9 years ago
补充说明一下:第一个问题,0.22.1没实现预想机制,但是连��
�上远程解析的ip,最后还是会读取hosts_0,而这一版干脆不读�
��了,造成twitter也连不上
第二个问题,除了本issue一开始所述问题,0.22.1判断机制比较
正常,不会出现这么多No available IP found for ***

Original comment by binkto...@gmail.com on 26 Jun 2013 at 5:09

GoogleCodeExporter commented 9 years ago
208.80.154.225这个dns解析的ip并不是连接不上,而是ssl协商失败�
��可能是墙的原因

修改了一下代码,增加了Direct时设置hosts优先级
如果需要优先读取hosts,需要在spac中指定;否则优先读取dns��
�录;例如
  {
    "Protocol" : "https",
    "Host" : ["wikipedia.org", "*.wikipedia.org","wikimedia.org", "wikibooks.org", "wikinews.org", "wikiquote.org", "wiktionary.org", "wikimediafoundation.org", "mediawiki.org"],
    "Proxy":["Direct", "C4"],
    "Attr":  ["PreferHosts"]
  },

Original comment by yinqiwen@gmail.com on 26 Jun 2013 at 2:47

Attachments:

GoogleCodeExporter commented 9 years ago
great!这一版完美工作,基本达到预想的效果了。
PS:你说的那个ssl协商失败的IP半个月前被干掉了443端口,208.
80.152.201这个IP目前还是有效的。我发起这个issue就是为了这个
问题。
至少对于https网站,hosts是最有效和高效的办法。你丫污染dns�
��封IP,封端口,我一条hosts搞定,实在没辙再祭出C4。呵呵,
墙和没墙又有什么区别呢?
感谢作者!

Original comment by binkto...@gmail.com on 26 Jun 2013 at 5:52

GoogleCodeExporter commented 9 years ago
 能编个linux版的吗?我这最后报错
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: i386 
architecture of input file `/tmp/go-link-KYdsZj/000000.o' is incompatible with 
i386:x86-64 output
collect2: error: ld returned 1 exit status
/usr/lib64/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit 
status 0x100
这啥情况?我这64位系统啊,怎么会有i386 architecture of input 
file

Original comment by binkto...@gmail.com on 29 Jun 2013 at 6:05

GoogleCodeExporter commented 9 years ago
ld try to link main/icon.syso, which is a PE-i386 format.
Delete it and go build.

Original comment by xhkbmdru...@gmail.com on 28 Dec 2013 at 8:58