14.5.27以来。谷歌又打不开了。

从网上找了些国内的googleserverIP,例如以下:

const char* g_google_ips[18] = {
"203.208.48.151", "203.208.46.176", "203.208.46.147",
"203.208.46.212", "203.208.46.158", "203.208.46.180",
"203.208.46.198", "203.208.41.150", "203.208.41.151",
"203.208.41.135", "203.208.41.142", "203.116.165.221",
"203.116.165.224", "203.116.165.235", "203.116.165.207",
"203.116.165.223", "203.116.165.231", "203.116.165.160",
};

但每次手动选择一个IP来打开的话,还不知道他速度好不好,所以我做了这么个小程序analyse.exe:

依次ping每一个IP,计算其响应时间,选取最快的一个,写入一个bat文件。内容为:

sprintf(cmd, "start explorer http://%s", g_google_ips[fastest_ndx]);

使用exporer会用ie来打开谷歌站点。

explorer能够替换为自己的浏览器路径或名称,如chrome。

直接执行这个批处理文件就可以打开google站点。下次感觉这个IP变卡了,能够再次执行一下analyse.exe。

完整源码例如以下:

typedef struct icmp_hdr
{
unsigned char icmp_type; // 消息类型
unsigned char icmp_code; // 代码
unsigned short icmp_checksum; // 校验和
// 以下是回显头
unsigned short icmp_id; // 用来惟一标识此请求的ID号,通常设置为进程ID
unsigned short icmp_sequence; // 序列号
unsigned long icmp_timestamp; // 时间戳
} ICMP_HDR, *PICMP_HDR; const char* g_google_ips[18] = {
"203.208.48.151", "203.208.46.176", "203.208.46.147",
"203.208.46.212", "203.208.46.158", "203.208.46.180",
"203.208.46.198", "203.208.41.150", "203.208.41.151",
"203.208.41.135", "203.208.41.142", "203.116.165.221",
"203.116.165.224", "203.116.165.235", "203.116.165.207",
"203.116.165.223", "203.116.165.231", "203.116.165.160",
}; USHORT checksum(USHORT* buff, int size)
{
unsigned long cksum = 0;
while(size>1)
{
cksum += *buff++;
size -= sizeof(USHORT);
}
// 是奇数
if(size)
{
cksum += *(UCHAR*)buff;
}
// 将32位的chsum高16位和低16位相加。然后取反
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return (USHORT)(~cksum);
} BOOL SetTimeout(SOCKET s, int nTime, BOOL bRecv)
{
int ret = ::setsockopt(s, SOL_SOCKET,
bRecv ? SO_RCVTIMEO : SO_SNDTIMEO, (char*)&nTime, sizeof(nTime));
return ret != SOCKET_ERROR;
} int ping(const char* dst_ip)
{
SOCKET sRaw = ::socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); SetTimeout(sRaw, 1000, TRUE); SOCKADDR_IN dest;
dest.sin_family = AF_INET;
dest.sin_port = htons(0);
dest.sin_addr.S_un.S_addr = inet_addr(dst_ip); // 创建ICMP封包
char buff[sizeof(ICMP_HDR) + 32];
ICMP_HDR* pIcmp = (ICMP_HDR*)buff;
pIcmp->icmp_type = 8; // 请求一个ICMP回显
pIcmp->icmp_code = 0;
pIcmp->icmp_id = (USHORT)::GetCurrentProcessId();
pIcmp->icmp_checksum = 0;
pIcmp->icmp_sequence = 0;
memset(&buff[sizeof(ICMP_HDR)], 'E', 32); USHORT nSeq = 0;
char recvBuf[1024];
SOCKADDR_IN from;
int nLen = sizeof(from);
int avr_time = 0;
int nCount = 0;
while(TRUE)
{
int nRet;
if(nCount++ == 4)
break;
pIcmp->icmp_checksum = 0;
pIcmp->icmp_timestamp = ::GetTickCount();
pIcmp->icmp_sequence = nSeq++;
pIcmp->icmp_checksum = checksum((USHORT*)buff, sizeof(ICMP_HDR) + 32);
nRet = ::sendto(sRaw, buff, sizeof(ICMP_HDR) + 32, 0,
(SOCKADDR *)&dest, sizeof(dest));
if(nRet == SOCKET_ERROR)
{
printf(" sendto() failed: %d \n", ::WSAGetLastError());
return -1;
}
nRet = ::recvfrom(sRaw, recvBuf, 1024, 0, (sockaddr*)&from, &nLen);
if(nRet == SOCKET_ERROR)
{
if(::WSAGetLastError() == WSAETIMEDOUT)
{
printf(" timed out\n");
continue;
}
printf(" recvfrom() failed: %d\n", ::WSAGetLastError());
return -1;
} int nTick = ::GetTickCount();
if(nRet < sizeof(IPHeader) + sizeof(ICMP_HDR))
{
printf(" Too few bytes from %s \n", ::inet_ntoa(from.sin_addr));
} ICMP_HDR* pRecvIcmp = (ICMP_HDR*)(recvBuf + 20); // (ICMP_HDR*)(recvBuf + sizeof(IPHeader));
if(pRecvIcmp->icmp_type != 0) // 回显
{
printf(" nonecho type %d recvd \n", pRecvIcmp->icmp_type);
return -1;
} if(pRecvIcmp->icmp_id != ::GetCurrentProcessId())
{
printf(" someone else's packet! \n");
return -1;
} printf(" %d bytes from %s:", nRet, inet_ntoa(from.sin_addr));
printf(" icmp_seq = %d. ", pRecvIcmp->icmp_sequence);
printf(" time: %d ms", nTick - pRecvIcmp->icmp_timestamp);
avr_time += nTick - pRecvIcmp->icmp_timestamp;
printf(" \n"); ::Sleep(1000);
}
::closesocket(sRaw);
avr_time /= 4;
return avr_time;
}<pre code_snippet_id="385396" snippet_file_name="blog_20140610_3_201928" name="code" class="cpp">
int main()
{
static const int MAX_NUM = 18;
int ret_times[MAX_NUM] = {0};
int min_ret = 1000;
int fastest_ndx = 0;
printf("start analyze the speed of google's ips.\n");
for(int i = 0; i < MAX_NUM; i++)
{
printf("ping %s\n", g_google_ips[i]);
ret_times[i] = ping(g_google_ips[i]);
if(ret_times[i] != -1 && min_ret > ret_times[i])
{
min_ret = ret_times[i];
fastest_ndx = i;
}
printf("average time from %s is %d ms.\n\n",
g_google_ips[i], ret_times[i]);
} printf("analyze over, fastest google ip is %s, average time %d ms.\n",
g_google_ips[fastest_ndx], min_ret);
const char* file_name = "google.bat";
char cmd[1024] = {0};
sprintf(cmd, "start explorer http://%s", g_google_ips[fastest_ndx]);
::DeleteFile(file_name);
FILE* file = NULL;
file = fopen(file_name, "wb");
if(file)
{
fwrite(cmd, 1, strlen(cmd), file);
fclose(file);
printf("now you can run google.bat to open the fastest www.google.com!\n");
}
return 0;
}



google打不开解决的方法的更多相关文章

  1. IE浏览器打不开解决的方法

    windows 7和windows 8上的IE浏览器打不开.非常可能是权限问题,解决的方法: 点击"開始"-"执行",输入"regedit" ...

  2. 谷歌google搜索打不开、谷歌gmail邮箱及相关服务无法登录的解决的方法

    歌打不开 google打不开,与中国大陆封杀有关,可是主要是由于近期googleserver在全球范围内又一次进行了布局调整. 解决的方法是仅仅要改动用户本地计算机hosts文件就能够了. 一.Win ...

  3. 北邮iptv用WindowsMediaplayer打不开的解决的方法

    前言:之前我的iptv能够用,可是有次我安装了realplayer,它就偷偷把iptv文件的默认打开方式给篡改了,卸载了                  realplayer之后,iptv不能直接用 ...

  4. 在字符串资源文件里加入HTML元素,直接使用字符串资源,HTML元素没起作用的解决的方法

    escape  html  in string resource 一. 需求描写叙述 给TextView赋值res资源库中的字符串资源,注意这里是一个string资源,要实现以下的效果 "未 ...

  5. Rhythmbox中文乱码解决的方法

    转自:http://hi.baidu.com/morgensonne/item/3470aef58747abde6325d2d9 今天在网络上找到了一个比較好的解决Rhythmbox中文乱码的问题的方 ...

  6. Rhythmbox乱码的解决的方法

    近期尝试 Listen 和 Banshee 才发现,Rhythmbox 上出现的 mp3乱码问题依然,并且更加严重,想要彻底弄清和解决必须搞清两点,第一, mp3 标签类型和编码,第二,各种播放器对 ...

  7. Android Eclipseproject开发中的常见调试问题(二)android.os.NetworkOnMainThreadException 异常的解决的方法

    android.os.NetworkOnMainThreadException 异常的解决的方法. 刚开是把HttpURLConnectionnection 打开连接这种方法放在UI线程里了,可能不是 ...

  8. Chrome 对于 glyphicon 字体图标不显示的解决的方法

    在将Chome默认字体渲染为微软雅黑后,部分字体图标显示为方框,这里Chome扩展文档提供的解决的方法为: 找到  custom.css 文件,路径为: C:\Users\(username)\App ...

  9. Android Studio关于USB device not found的解决的方法

    Android Studio关于USB device not found的解决的方法 我们使用Android Studio进行Android开发时.当我们使用真机进行调试时.非常可能会出现USB de ...

随机推荐

  1. as 汇编器

    [root@localhost ~]# cat .s .file "write.s" .section .rodata hello: .string "hello, wo ...

  2. Android中的资源与国际化!

    Android中的资源与国际化的问题,通常我们新建一个Android工程,目录结构如下图所示: 我们主要看一下layout与values目录,layout里的xml文件的我们应用使用布局的文件,val ...

  3. EF Code First 学习笔记:表映射 多个Entity到一张表和一个Entity到多张表

      多个实体映射到一张表 Code First允许将多个实体映射到同一张表上,实体必须遵循如下规则: 实体必须是一对一关系 实体必须共享一个公共键 观察下面两个实体: public class Per ...

  4. UTF-8,Unicode,GBK,希腊字母读法,ASCII码表,HTTP错误码,URL编码表,HTML特殊字符,汉字编码简明对照表

    UNICODE,GBK,UTF-8区别 UNICODE,GBK,UTF-8区别    简单来说,unicode,gbk和大五码就是编码的值,而utf-8,uft-16之类就是这个值的表现形式.而前面那 ...

  5. iOS:UIButton按钮的详解

    UIButton的详细介绍: 一.按钮具有的属性: @property(nonatomic,readonly) UIButtonType buttonType;  //按钮形状类型 @property ...

  6. Objective-C:NSMutableArray类的常见操作

    可变数组NSMutableArray的内容大小是可变的,因此它的常见操作无非增删该查, 具体一些就是:创建.添加.删除.替换.插入.清空等等.. // //  main.m //  02-NSMuta ...

  7. 带你走进EJB--它都有哪些Bean

    通过前面一系列EJB的博客,我们已经对EJB有了一个宏观的了解.为够更好的在企业项目中使用EJB,我们很有必要对EJB的一些基本内容进行深入,这次我们主要进行的主题是Enterprise Java B ...

  8. jwplayer 隐藏属性方法记载

    jwplayer().getPosition(): //播放了多少秒 jwplayer('playerdiv').play(); || jwplayer(0).play(true / false); ...

  9. 可进可退,jQuery图片、视频、flash播放插件prettyPhoto使用记录

    一.prettyPhoto简介 prettyPhoto是一款基于jquery的轻量级的lightbox图片播放浏览插件,它不仅支持图片,还同时支持视频.flash.YouTube.iframe和aja ...

  10. php CURL 请求头和响应头获取

    1.从CURL中获取响应头 $oCurl = curl_init(); // 设置请求头, 有时候需要,有时候不用,看请求网址是否有对应的要求 $header[] = "Content-ty ...