怎样才能让internet上的两台机子互相ping通?

wangwpf 2003-10-15 11:19:25
不知道大家有没有试过,随便ping一个QQ上的好友,10个中有7可能都是ping不通的,可是却能通信,并且如果好友的机子上提供FTP或HTTP服务的话,直接打对方的FTP或HTTP服务的IP确可以访问,不知道为什么??
有没有什么方法,做个什么样的程序可以让internet中任意两台机子都可以ping通呢?
...全文
203 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
killme2008 2003-10-25
  • 打赏
  • 举报
回复
能够通过防火墙就是伪装成服务命令来实现的
royoddy 2003-10-24
  • 打赏
  • 举报
回复
如果想要ping通的话,那么就把你的ping命令伪装成ftp或者www服务,这样就能够绕过防火墙了。
vagerent 2003-10-24
  • 打赏
  • 举报
回复
qq一般网络不好是会给你转发的,所以ip不一定是他的真实ip
Swallowdeng_cq 2003-10-24
  • 打赏
  • 举报
回复
如果只是测试通不通,可以用gethostbyname 、 gethostbyaddr判它的返回值
wangwpf 2003-10-17
  • 打赏
  • 举报
回复
我知道有代理和防火墙拦截,但是这些Ping不通的机子上如果有ftp或www服务的话,却可以访问这些服务资源,这说明两机还是可以通讯的。我见到一个软件就可能实现那些互ping不通的机子让他们可以ping通,不管对方的机子上有什么样的防火墙都可以
delphizd 2003-10-15
  • 打赏
  • 举报
回复
//////////////////////////////////
PING命令讲解
对于Windows下ping指令相信大家已经再熟悉不过了,但是能把ping的功能发挥到最大的人却并不是很多,当然我也并不是说我可以让ping发挥最大的功能,我也只不过经常用ping这个工具,也总结了一些小经验,现在和大家分享一下。

 

  现在我就参照ping指令的辅助说明来给大家讲我使用ping时会用到的技巧,ping只有在安装了TCP/IP通讯协议以后才可以使用:

  ping [-t] [-a] [-n count] [-l length] [-f] [-i ttl] [-v tos] [-r count] [-s count] [[-j computer-list] | [-k computer-list]] [-w timeout] destination-list

  Options:

  -t Ping the specified host until stopped.To see statistics and continue - type Control-Break;To stop - type Control-C.

  不停的ping地方主机,直到你按下Control-C。

  此功能?有什么特别的技巧,不过可以配合其它参数使用,将在下面提到。

  -a Resolve addresses to hostnames.

  解析计算机NetBios名。

  例:C:\>ping -a 192.168.1.21

  Pinging iceblood.yofor.com [192.168.1.21] with 32 bytes of data:

  Reply from 192.168.1.21: bytes=32 time<10ms TTL=254

  Reply from 192.168.1.21: bytes=32 time<10ms TTL=254

  Reply from 192.168.1.21: bytes=32 time<10ms TTL=254

  Reply from 192.168.1.21: bytes=32 time<10ms TTL=254

  Ping statistics for 192.168.1.21:

  Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:

  Minimum = 0ms, Maximum = 0ms, Average = 0ms

  从上面就可以知道IP为192.168.1.21的计算机NetBios名为iceblood.yofor.com。

  -n count Number of echo requests to send.

  发送count指定的Echo数据包数。

  在默认情况下,一般都只发送四个数据包,通过这个命令可以自己定义发送的个数,对衡量网络速度很有帮助,比如我想测试发送50个数据包的返回的平均时间为多少,最快时间为多少,最慢时间为多少就可以通过以下?知:

  C:\>ping -n 50 202.103.96.68

  Pinging 202.103.96.68 with 32 bytes of data:

  Reply from 202.103.96.68: bytes=32 time=50ms TTL=241

  Reply from 202.103.96.68: bytes=32 time=50ms TTL=241

  Reply from 202.103.96.68: bytes=32 time=50ms TTL=241

  Request timed out.

  ………………

  Reply from 202.103.96.68: bytes=32 time=50ms TTL=241

  Reply from 202.103.96.68: bytes=32 time=50ms TTL=241

  Ping statistics for 202.103.96.68:

  Packets: Sent = 50, Received = 48, Lost = 2 (4% loss),Approximate round trip times in milli-seconds:

  Minimum = 40ms, Maximum = 51ms, Average = 46ms

  从以上我就可以知道在给202.103.96.68发送50个数据包的过程当中,返回了48个,其中有两个由于未知原因丢失,这48个数据包当中返回速度最快为40ms,最慢为51ms,平均速度为46ms。

  -l size Send buffer size.

  定义echo数据包大小。

  在默认的情?下windows的ping发送的数据包大小为32byt,我们也可以自己定义它的大小,但有一个大小的限制,就是最大只能发送65500byt,也许有人会问为什么要限制到65500byt,因为Windows系列的系统都有一个安全漏洞(也许还包括其它系统)就是当向对方一次发送的数据包大于或等于65532时,对方就很有可能当机,所以微软公司为了解决这一安全漏洞于是限制了ping的数据包大小。虽然微软公司已经做了此限制,但这个参数配合其它参数以后危害依然非常强大,比如我们就可以通过配合-t参数来实现一个带有攻击性的指令:(以下介绍带有危险性,只用于试验,请勿轻易施于别人计算机上,否?后果自负)

  C:\>ping -l 65500 -t 192.168.1.21

  Pinging 192.168.1.21 with 65500 bytes of data:

  Reply from 192.168.1.21: bytes=65500 time<10ms TTL=254

  Reply from 192.168.1.21: bytes=65500 time<10ms TTL=254

  ………………

  这样它就会不停的向192.168.1.21计算机发送大小为65500byt的数据包,如果你只有一台计算机也许?有什么效果,但如果有很多台计算机那么就可以使对方完全瘫痪,我曾经就做过这样的试验,当我同时使用10台以上计算机ping一台Win2000Pro系统的计算机时,不到5分钟对方的网络就已经完全瘫痪,网络严重堵塞,HTTP和FTP服务完全停止,由此可见威力非同小可。

  -f Set Don't Fragment flag in packet.

  在数据包中发送“不要分段”标志。

  在一般你所发送的数据包都会通过路由分段再发送给对方,加上此参数以后路由就不会再分段处理。

  -i TTL Time To Live.

  指定TTL值在对方的系统里停留的时间。

  此参数同样是帮助你检查网络运转情况的。

  -v TOS Type Of Service.

  将“服务类型”字段设置为tos指定的值。

  -r count Record route for count hops.

  在“记录路由”字段中记录伝出和返回数据包的路由。

  在一般情况下你发送的数据包是通过一个个路由才到达对方的,但到底是经过了哪些路由呢?通过此参数就可以设定你想探测经过的路由的个数,不过限制在了9个,也就是说你只能跟踪到9个路由,如果想探测更多,可以通过其它命令实现,我将在以后的文章中给大家讲解。以下为筥例:

  C:\>ping -n 1 -r 9 202.96.105.101(发送一个数据包,最多记录9个路由)

  Pinging 202.96.105.101 with 32 bytes of data:

  Reply from 202.96.105.101: bytes=32 time=10ms TTL=249

  Route: 202.107.208.187 ->

  202.107.210.214 ->

  61.153.112.70 ->

  61.153.112.89 ->

  202.96.105.149 ->

  202.96.105.97 ->

  202.96.105.101 ->

  202.96.105.150 ->

  61.153.112.90

  Ping statistics for 202.96.105.101:

  Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

  Approximate round trip times in milli-seconds:

  Minimum = 10ms, Maximum = 10ms, Average = 10ms

  从上面我就可以知道从我的计算机到202.96.105.101一共通过了202.107.208.187,202.107.210.214 , 61.153.112.70 , 61.153.112.89 , 202.96.105.149 , 202.96.105.97这几个路由。

  -s count Timestamp for count hops.

  指定count指定的?点数的时间戳。

  此参数和-r差不多,只是这个参数不记录数据包返回所经过的路由,最多也只记录4个。

  -j host-list Loose source route along host-list.

  利用computer-list指定的计算机列表路由数据包。连续计算机可以被中间关网?分隔(路由稀疏源)IP允许的最大?量为9。

  -k host-list Strict source route along host-list.

  利用computer-list指定的计算机列表路由数据包。连续计算机不能被中间网?分隔(路由?格源)IP允许的最大数量为9。

  -w timeout Timeout in milliseconds to wait for each reply.

  指定超时间隔,单位为毫秒。

  此参数?有什么其它技巧。

  ping指令的其它技巧:在一般情况下还可以通过ping对方让对方返回给你的TTL值大小,粗略的判断目标主机的系统类型是Windows系列还是UNIX/Linux系列,一般情况下Windows系列的系?返回的TTL值在100-130之间,而UNIX/Linux系列的系统返回的TTL值在240-255之间,当然TTL的值在对方的主机里是可以修改的,Windows系列的系?可以通过修改注?表以下键值实现:

  [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]

  "DefaultTTL"=dword:000000ff

  255---FF

  128---80

  64----40

  32----20

  好了,ping命令也基本上完全讲解完了,其中还有-j,-k参数我还没有详细说明,由于某些原因也包括我自己所收集的资料过少这里也?有向大家详细介绍,请大家见谅,如果在看了这篇文章的朋友当中有知道得比我更多的,以及其它使用技巧的也希望您能告知我,并在此先谢过。

-=-= 由原先 SC教学文件区 转至此 =-=- 原发表人: KTB

C:\>ping /?

Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] destination-list

Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply
delphizd 2003-10-15
  • 打赏
  • 举报
回复
// Make sure this is an ICMP reply to something we sent!
//
if (icmphdr->i_id != (USHORT)GetCurrentProcessId())
{
printf("someone else's packet!\n");
return ;
}
printf("%d bytes from %s:", bytes, inet_ntoa(from->sin_addr));
printf(" icmp_seq = %d. ", icmphdr->i_seq);
printf(" time: %d ms", tick - icmphdr->timestamp);
printf("\n");

icmpcount++;
return;
}

void ValidateArgs(int argc, char **argv)
{
int i;

bRecordRoute = FALSE;
lpdest = NULL;
datasize = DEF_PACKET_SIZE;

for(i = 1; i < argc; i++)
{
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
{
switch (tolower(argv[i][1]))
{
case 'r': // Record route option
bRecordRoute = TRUE;
break;
default:
usage(argv[0]);
break;
}
}
else if (isdigit(argv[i][0]))
datasize = atoi(argv[i]);
else
lpdest = argv[i];
}
}

int main(int argc, char **argv)
{

WSADATA wsaData;
SOCKET sockRaw = INVALID_SOCKET;
struct sockaddr_in dest,
from;
int bread,
fromlen = sizeof(from),
timeout = 1000,
ret;
char *icmp_data = NULL,
*recvbuf = NULL;
unsigned int addr = 0;
USHORT seq_no = 0;
struct hostent *hp = NULL;
IpOptionHeader ipopt;


if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
printf("WSAStartup() failed: %d\n", GetLastError());
return -1;
}
ValidateArgs(argc, argv);

sockRaw = WSASocket (AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,
WSA_FLAG_OVERLAPPED);
if (sockRaw == INVALID_SOCKET)
{
printf("WSASocket() failed: %d\n", WSAGetLastError());
return -1;
}
if (bRecordRoute)
{
// Setup the IP option header to go out on every ICMP packet
//
ZeroMemory(&ipopt, sizeof(ipopt));
ipopt.code = IP_RECORD_ROUTE; // Record route option
ipopt.ptr = 4; // Point to the first addr offset
ipopt.len = 39; // Length of option header

ret = setsockopt(sockRaw, IPPROTO_IP, IP_OPTIONS,
(char *)&ipopt, sizeof(ipopt));
if (ret == SOCKET_ERROR)
{
printf("setsockopt(IP_OPTIONS) failed: %d\n",
WSAGetLastError());
}
}
// Set the send/recv timeout values
//
bread = setsockopt(sockRaw, SOL_SOCKET, SO_RCVTIMEO,
(char*)&timeout, sizeof(timeout));
if(bread == SOCKET_ERROR)
{
printf("setsockopt(SO_RCVTIMEO) failed: %d\n",
WSAGetLastError());
return -1;
}
timeout = 1000;
bread = setsockopt(sockRaw, SOL_SOCKET, SO_SNDTIMEO,
(char*)&timeout, sizeof(timeout));
if (bread == SOCKET_ERROR)
{
printf("setsockopt(SO_SNDTIMEO) failed: %d\n",
WSAGetLastError());
return -1;
}
memset(&dest, 0, sizeof(dest));
//
// Resolve the endpoint's name if necessary
//
dest.sin_family = AF_INET;
if ((dest.sin_addr.s_addr = inet_addr(lpdest)) == INADDR_NONE)
{
if ((hp = gethostbyname(lpdest)) != NULL)
{
memcpy(&(dest.sin_addr), hp->h_addr, hp->h_length);
dest.sin_family = hp->h_addrtype;
printf("dest.sin_addr = %s\n", inet_ntoa(dest.sin_addr));
}
else
{
printf("gethostbyname() failed: %d\n",
WSAGetLastError());
return -1;
}
}

//
// Create the ICMP packet
//
datasize += sizeof(IcmpHeader);

icmp_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
MAX_PACKET);
recvbuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
MAX_PACKET);
if (!icmp_data)
{
printf("HeapAlloc() failed: %d\n", GetLastError());
return -1;
}
memset(icmp_data,0,MAX_PACKET);
FillICMPData(icmp_data,datasize);
//
// Start sending/receiving ICMP packets
//
while(1)
{
static int nCount = 0;
int bwrote;

if (nCount++ == 4)
break;

((IcmpHeader*)icmp_data)->i_cksum = 0;
((IcmpHeader*)icmp_data)->timestamp = GetTickCount();
((IcmpHeader*)icmp_data)->i_seq = seq_no++;
((IcmpHeader*)icmp_data)->i_cksum =
checksum((USHORT*)icmp_data, datasize);

bwrote = sendto(sockRaw, icmp_data, datasize, 0,
(struct sockaddr*)&dest, sizeof(dest));
if (bwrote == SOCKET_ERROR)
{
if (WSAGetLastError() == WSAETIMEDOUT)
{
printf("timed out\n");
continue;
}
printf("sendto() failed: %d\n", WSAGetLastError());
return -1;
}
if (bwrote < datasize)
{
printf("Wrote %d bytes\n", bwrote);
}
bread = recvfrom(sockRaw, recvbuf, MAX_PACKET, 0,
(struct sockaddr*)&from, &fromlen);
if (bread == SOCKET_ERROR)
{
if (WSAGetLastError() == WSAETIMEDOUT)
{
printf("timed out\n");
continue;
}
printf("recvfrom() failed: %d\n", WSAGetLastError());
return -1;
}
DecodeICMPHeader(recvbuf, bread, &from);

Sleep(1000);
}
// Cleanup
//
if (sockRaw != INVALID_SOCKET)
closesocket(sockRaw);
HeapFree(GetProcessHeap(), 0, recvbuf);
HeapFree(GetProcessHeap(), 0, icmp_data);

WSACleanup();
return 0;
}

delphizd 2003-10-15
  • 打赏
  • 举报
回复
ping的源程序

// Module Name: Ping.c
//
// Description:
// This sample illustrates how an ICMP ping app can be written
// using the SOCK_RAW socket type and IPPROTO_ICMP protocol.
// By creating a raw socket, the underlying layer does not change
// the protocol header so that when we submit the ICMP header
// nothing is changed so that the receiving end will see an
// ICMP packet. Additionally, we use the record route IP option
// to get a round trip path to the endpoint. Note that the size
// of the IP option header that records the route is limited to
// nine IP addresses.
//
// Compile:
// cl -o Ping Ping.c ws2_32.lib /Zp1
//
// Command Line Options/Parameters:
// Ping [host] [packet-size]
//
// host String name of host to ping
// packet-size Integer size of packet to send
// (smaller than 1024 bytes)
//
//#pragma pack(1)

#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include

#define IP_RECORD_ROUTE 0x7
//
// IP header structure
//
typedef struct _iphdr
{
unsigned int h_len:4; // Length of the header
unsigned int version:4; // Version of IP
unsigned char tos; // Type of service
unsigned short total_len; // Total length of the packet
unsigned short ident; // Unique identifier
unsigned short frag_and_flags; // Flags
unsigned char ttl; // Time to live
unsigned char proto; // Protocol (TCP, UDP etc)
unsigned short checksum; // IP checksum

unsigned int sourceIP;
unsigned int destIP;
} IpHeader;



#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // Minimum 8-byte ICMP packet (header)

//
// ICMP header structure
//
typedef struct _icmphdr
{
BYTE i_type;
BYTE i_code; // Type sub code
USHORT i_cksum;
USHORT i_id;
USHORT i_seq;
// This is not the standard header, but we reserve space for time
ULONG timestamp;
} IcmpHeader;

//
// IP option header - use with socket option IP_OPTIONS
//
typedef struct _ipoptionhdr
{
unsigned char code; // Option type
unsigned char len; // Length of option hdr
unsigned char ptr; // Offset into options
unsigned long addr[9]; // List of IP addrs
} IpOptionHeader;

#define DEF_PACKET_SIZE 32 // Default packet size
#define MAX_PACKET 1024 // Max ICMP packet size
#define MAX_IP_HDR_SIZE 60 // Max IP header size w/options

BOOL bRecordRoute;
int datasize;
char *lpdest;

//
// Function: usage
//
// Description:
// Print usage information
//
void usage(char *progname)
{
printf("usage: ping -r [data size]\n");
printf(" -r record route\n");
printf(" host remote machine to ping\n");
printf(" datasize can be up to 1KB\n");
ExitProcess(-1);
}
//
// Function: FillICMPData
//
// Description:
// Helper function to fill in various fields for our ICMP request
//
void FillICMPData(char *icmp_data, int datasize)
{
IcmpHeader *icmp_hdr = NULL;
char *datapart = NULL;

icmp_hdr = (IcmpHeader*)icmp_data;
icmp_hdr->i_type = ICMP_ECHO; // Request an ICMP echo
icmp_hdr->i_code = 0;
icmp_hdr->i_id = (USHORT)GetCurrentProcessId();
icmp_hdr->i_cksum = 0;
icmp_hdr->i_seq = 0;

datapart = icmp_data + sizeof(IcmpHeader);
//
// Place some junk in the buffer
//
memset(datapart,'E', datasize - sizeof(IcmpHeader));
}

//
// Function: checksum
//
// Description:
// This function calculates the 16-bit one's complement sum
// of the supplied buffer (ICMP) header
//
USHORT checksum(USHORT *buffer, int size)
{
unsigned long cksum=0;

while (size > 1)
{
cksum += *buffer++;
size -= sizeof(USHORT);
}
if (size)
{
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
//
// Function: DecodeIPOptions
//
// Description:
// If the IP option header is present, find the IP options
// within the IP header and print the record route option
// values
//
void DecodeIPOptions(char *buf, int bytes)
{
IpOptionHeader *ipopt = NULL;
IN_ADDR inaddr;
int i;
HOSTENT *host = NULL;

ipopt = (IpOptionHeader *)(buf + 20);

printf("RR: ");
for(i = 0; i < (ipopt->ptr / 4) - 1; i++)
{
inaddr.S_un.S_addr = ipopt->addr[i];
if (i != 0)
printf(" ");
host = gethostbyaddr((char *)&inaddr.S_un.S_addr,
sizeof(inaddr.S_un.S_addr), AF_INET);
if (host)
printf("(%-15s) %s\n", inet_ntoa(inaddr), host->h_name);
else
printf("(%-15s)\n", inet_ntoa(inaddr));
}
return;
}

//
// Function: DecodeICMPHeader
//
// Description:
// The response is an IP packet. We must decode the IP header to
// locate the ICMP data.
//
void DecodeICMPHeader(char *buf, int bytes,
struct sockaddr_in *from)
{
IpHeader *iphdr = NULL;
IcmpHeader *icmphdr = NULL;
unsigned short iphdrlen;
DWORD tick;
static int icmpcount = 0;

iphdr = (IpHeader *)buf;
// Number of 32-bit words * 4 = bytes
iphdrlen = iphdr->h_len * 4;
tick = GetTickCount();

if ((iphdrlen == MAX_IP_HDR_SIZE) && (!icmpcount))
DecodeIPOptions(buf, bytes);

if (bytes < iphdrlen + ICMP_MIN)
{
printf("Too few bytes from %s\n",
inet_ntoa(from->sin_addr));
}
icmphdr = (IcmpHeader*)(buf + iphdrlen);

if (icmphdr->i_type != ICMP_ECHOREPLY)
{
printf("nonecho type %d recvd\n", icmphdr->i_type);
return;
}
我不懂电脑 2003-10-15
  • 打赏
  • 举报
回复
ping不通,很多原因都是对方使用了代理或防火墙
tanqth 2003-10-15
  • 打赏
  • 举报
回复
有的机器是加了防火墙的,不PING不通的。

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧