curl --connect-timeout 判断国内外网络windows 批处理
2016-01-22 10:12
671 查看
1.下载编译curl
curl 下载地址:http://curl.haxx.se/download.html ,下载后解压到一个目录,使用vs开发者工具里的 “Visual Studio 命令提示(2010)” 打开命令行,
切换到源码目录 F:\curl-7.46.0\winbuild\,使用命令 nmake/f Makefile.vc mode=static 编译一下,在 F:\curl-7.46.0\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\bin 目录下生成curl.exe 文件。
打开命令行切换到curl.exe目录,查看版本 curl -V
curl 7.46.0 (i386-pc-win32) libcurl/7.46.0 WinSSL WinIDN
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
如果在使用curl时出现 curl: (1) Protocol https not supported or disabled in libcurl错误,首先检查一下用的curl.exe是否支持https协议.
2.知乎上有个根据curl --connect-timeout https://google.com 返回值判断是否是国内网络的代码段
链接地址:https://www.zhihu.com/question/30262900
# Guess your location, you know it.
location='oversea'
curl --connect-timeout 1 https://google.com 2>&1 >/dev/null
ret=$? if [ $ret -ne 0 ]; then
location='cn'
else
.......
这里翻译一个window下批处理版本
curl 下载地址:http://curl.haxx.se/download.html ,下载后解压到一个目录,使用vs开发者工具里的 “Visual Studio 命令提示(2010)” 打开命令行,
切换到源码目录 F:\curl-7.46.0\winbuild\,使用命令 nmake/f Makefile.vc mode=static 编译一下,在 F:\curl-7.46.0\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\bin 目录下生成curl.exe 文件。
打开命令行切换到curl.exe目录,查看版本 curl -V
curl 7.46.0 (i386-pc-win32) libcurl/7.46.0 WinSSL WinIDN
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
如果在使用curl时出现 curl: (1) Protocol https not supported or disabled in libcurl错误,首先检查一下用的curl.exe是否支持https协议.
2.知乎上有个根据curl --connect-timeout https://google.com 返回值判断是否是国内网络的代码段
链接地址:https://www.zhihu.com/question/30262900
# Guess your location, you know it.
location='oversea'
curl --connect-timeout 1 https://google.com 2>&1 >/dev/null
ret=$? if [ $ret -ne 0 ]; then
location='cn'
else
.......
这里翻译一个window下批处理版本
@echo off set location='oversea' echo '当前位置:%location%' echo '访问http://www.baidu.com' rem -x 设置代理 rem --connect-timeout 1 连接超时1秒,命令正常执行结果为1指stdout标准输出, rem 就是控制台输出;2指stderr错误输出,这里 2>$1表示重定向到1, rem 然后再重定向到null,linux下是/dev/null,windows下是nul。 curl -x "http://192.168.0.6:8080" --connect-timeout 1 "http://www.baidu.com" 2>$1>nul rem errorlevel是个系统变量指上一条语句的执行结果,成功时等于0 echo '结果%errorlevel%' echo '访问https://google.com' curl -x "http://192.168.0.6:8080" --connect-timeout 1 "https://google.com" 2>$1>nul rem 这里是56,完整信息是 curl: (56) Proxy CONNECT aborted due to timeout echo '结果%errorlevel%' IF not errorlevel 0 then( set location='CN' ) echo '当前位置:%location%'
相关文章推荐
- ngcordova 监控网络制式改变
- HTTP protocal
- ios 开发网络篇 - 数据缓存
- HTTP对外接口,如何增加签名机制
- 九大全球网络攻击实时追踪系统盘点
- 《HTTP权威指南》-第7章 缓存
- 《HTTP权威指南》-第6章 代理
- 《HTTP权威指南》-第5章 Web服务器
- HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
- 提示网络状态并打开网络设置页面
- 金蝶盘点机条码数据採集器PDA,WIFI已经连接,可是PDA应用程序还是网络初始化不成功?
- 用AFNetworking3.0封装网络请求
- 流量的质量超重要!如何寻找高质量流量日入三百+
- VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射
- 基于流数据挖掘的网络流量异常检测及分析研究
- tcpdump
- vollery框架支持https
- VIEWGOOD(远古)承建大学校园网络电视台项目
- 现在就启用 HTTPS,免费的!
- ubuntu+web.py+fastcgi+lighttpd