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. HDOJ 4876 ZCC loves cards

    枚举组合,在不考虑连续的情况下推断能否够覆盖L...R,对随机数据是一个非常大的减枝. 通过检測的暴力计算一遍 ZCC loves cards Time Limit: 4000/2000 MS (Ja ...

  2. 埃及分解:将2/n分解成为1/x+1/y的格式

    算法 古埃及以前创造出灿烂的人类文明,他们的分数表示却非常令人不解.古埃及喜欢把一个分数分解为类似: 1/a + 1/b 的格式. 这里,a 和 b 必须是不同的两个整数,分子必须为 1 比方,2/1 ...

  3. 不用软件快速拥有几百个QQ群并都是管理员

    不用软件快速拥有几百个QQ群并都是管理员!快速拥有有几十万精准数据库的方法 !和快速收集上亿邮箱的思维方法(附上5种赚钱方法).pdf_免费高速下载|百度云 网盘-分享无限制 http://pan.b ...

  4. lol匹配算法

    这是Riot的Design Director Tom Cadwell专门为中国玩家写的解说匹配系统工作原理的帖子. 同一时候为了让大家更好的理解匹配系统,假设您认为您遇到了特别不公平的匹配,请回复游戏 ...

  5. Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied) nginx 启动失败

     Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied)     nginx 启动失败 ...

  6. Accepting PayPal in games(完整的Paypal在Unity的支付)

      Hello and welcome back to my blog! In this article I’m going to talk about the process of acceptin ...

  7. python测试开发django-5.模板templates

    前言 html是一个静态的语言,里面没法传一些动态参数,也就是一个写死的html页面.如果想实现在一个固定的html样式,传入不同的参数,这就可以用django的模板传参来解决. 模板参数 先在hel ...

  8. IOS学习笔记02---语言发展概述,计算机语言简介.

    IOS学习笔记02---语言发展概述,计算机语言简介. ------------------------------------------------------------------------ ...

  9. C#的几种写文件方法

    C#写文件处理操作在很多的开发项目中都会涉及,那么具体的实现方法是什么呢?这里向大家介绍三大方法,希望对你在开发应用中有所启发. 首先C#写文件处理操作必须先导入命名空间:using System.I ...

  10. JavaScript之深浅拷贝

    数组的浅拷贝 如果是数组,我们可以利用数组的一些方法比如:slice.concat 返回一个新数组的特性来实现拷贝.比如: , true, null, undefined]; var new_arr ...