对网络上的计算机执行 Ping 操作

发布于 2024-10-31 04:22:09 字数 936 浏览 1 评论 0原文

我是一名大学研究员,正在尝试业余 java2 编程。

我一直在学习 KnockKnockServer/Client Java2 教程,以使用 Java 套接字将字符串从一个程序发送到另一个程序。

http://download.oracle.com/javase/tutorial/networking/sockets /clientServer.html

可以在那里下载完整的源代码,它编译得很好,是使用 IP 让两个程序在 Java 中相互通信的一个很好的例子。

当我使用在同一台计算机上运行的服务器和客户端并且计算机名称为“localhost”时,这工作正常

kkSocket = new Socket("localhost", 4444);

并且当我在家庭网络上使用 InetAddress 时,它也可以在家里工作:

InetAddress myaddress = InetAddress.getByName("129.11.138.64");
kkSocket = new Socket(myaddress, 4444);

但是,当我尝试执行以下操作时:在大学机器上也是如此,它不起作用,因为它们位于某种代理后面,尽管两台机器彼此相邻并插入相邻的以太网端口。

问题:

当我无法完全控制两台机器所在的网络时,如何弄清楚如何让两台机器相互通信?我什至不知道如何让他们互相 ping 通。我访问了“www.whatismyip.com”来获取每台机器的外部IP,但这不起作用,我查看了下一个工作适配器IP和它们所在的网关,但仍然无法获取它们互相交谈。

任何想法。

谢谢!

I am a researcher at University and I'm trying my hand at a bit of amateur java2 programming.

I've been working through the KnockKnockServer/Client Java2 tutorial to send strings from one program to another using Java Sockets.

http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html

Full source can be downloaded there and it compiles nicely and is a great example of using IP's to get two programs to talk to each other in Java.

This works fine when I use both the server and the client running on the same machine and the machine name as "localhost"

kkSocket = new Socket("localhost", 4444);

And it also works at home when I use it on my home network with a InetAddress:

InetAddress myaddress = InetAddress.getByName("129.11.138.64");
kkSocket = new Socket(myaddress, 4444);

However when I try to do the same on the university machines it doesn't work because they are behind some kind of proxy despite the fact that the two machines are next to each other and plugged into adjacent ethernet ports.

Question:

How to I work out how to get the two machines to speak to each other, when I don't have full control of the network they are on? I can't even work out how to get them to ping each other. I have visited "www.whatismyip.com" to get the external ip's of each machine but that doesn't work, and I've looked at the next work adapters ip and the gateway they are on but still I can't get them to talk to each other.

Any ideas.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你在看孤独的风景 2024-11-07 04:22:09

在我看来,您的网络正在阻止端口 4444 上的流量。尝试其他端口,或确认允许端口 4444。

It sounds to me like your network is blocking traffic on port 4444. Try a different port, or confirm that port 4444 is allowed.

天暗了我发光 2024-11-07 04:22:09

这个问题有几个不同的部分:

1)两台机器可以相互连接吗?

您可以使用 Windows 和 *nix 中都可用的“ping”命令从命令行进行测试。 Ping 测试与指定机器的连接的存在性和可靠性。

2)路由可以过滤吗?

仅仅因为您可以 ping 通一台计算机,并不意味着它们之间没有防火墙或代理。您可以使用“tracert”命令找到两台机器之间的路由。路线中的步骤越多,可能阻止信号的因素就越多

3) Java 是否有防火墙?

仅仅因为它已安装,并不意味着它具有开放的网络访问权限。尝试获取一些 URL 或类似内容以查看 Java 是否具有网络连接。

4)端口是否被阻塞?

端口可以​​通过两种方式被阻止:其他应用程序正在使用它,或者防火墙正在限制侦听端口。如果是前者,Java 将无法将 Socket 连接到端口。如果是后者,请尝试不同的端口。没有什么可以阻止您同时运行 10000 个客户端并查看是否可以连接到其中任何一个。

5) 在 Java 中如何做到这一点?

Ping可以通过InetAddress.isReachable()来实现。

6) 我应该对刚刚出现的愤怒的网络管理员说什么?

“我不会扫描端口和网络!老实说!”寻找可用端口是一项基本的黑客操作。一些工作场所有自动工具来检查它,并会认为它是不合适的。

There are several different parts to this problem:

1) Can the two machines connect to each other?

You can test this from the command line with the "ping" command which is available in both Windows and *nix. Ping tests for the existence and reliability of a connection to the named machine.

2) Could the route be filtered?

Just because you can ping a machine, doesn't mean there is no firewall or proxy between them. You can find the route taken between the two machines with the "tracert" command. The more steps in the route, the more things that might stop your signal

3) Is Java firewalled?

Just because it is installed, does not mean it has open network access. Try fetching a few URLs or similar to see if Java has network connectivity.

4) Is the port blocked?

A port could be blocked in two ways: some other application is using it, or a firewall is limiting listening ports. If the former, Java will not be able to attach a Socket to the port. If the latter, try a different port. There is nothing to stop you running 10000 clients simultaneously and seeing if you can connect to any of them.

5) How do you do this in Java?

Ping can be implemented by InetAddress.isReachable().

6) What should I say to the angry Network Admin guy who has just turned up?

"I'm not port and network scanning! Honest!" Hunting for usable ports is a basic hacking operation. Some workplaces have automatic tools to check for it and will view it as inappropriate.

流云如水 2024-11-07 04:22:09

即使我也无法 ping 通我工作场所的两台机器。

您需要更改网络首选项或尝试以下操作:
(IE浏览器使用说明)
转到工具->互联网选项 ->局域网设置->高级。
向字段添加例外:“不要对以以下内容开头的地址使用代理服务器:”
输入网络 IP 起始编号,例如,如果您的网络有以 10.--.--.-- 开头的 IP 地址,请在字段中写入 10.*。

Even i cannot ping two machines at my work place.

you need to change the network preferences or try the following:
(instructions for IE)
Go to tools-> internet options -> lan settings -> advanced.
Add exceptions to the field: "Do not use proxy server for addresses beginning with:"
enter the networks ip starting numbers, for eg if your network has ip adds starting with 10.--.--.-- write 10.* in the field.

堇色安年 2024-11-07 04:22:09

您需要确保每台计算机都知道 LAN 上对方的私有 IP 地址(请参阅 ipconfig 或 ifconfig 命令)。每次设备连接到 LAN 上时(几乎),它都会发生变化,有时甚至在设备连接到 LAN 上时也会发生变化。

www.whatismyip.com 不会帮助您,因为它只会为您提供距离该服务器最近的路由器/NAT 的公共 IP 地址。无法保证它也是距离您的设备最近的一个。即使是这样,这些信息也是无用的,因为您(大多数情况下)无法预测 NAT 将如何将您的私有 IP 地址转换为公共 IP 地址。

即使您可以“猜测”该信息,路由器/NAT 也有可能不允许您在其后面(即在 LAN 上)使用此转换。

总而言之,请确保使用分配给设备的正确私有 IP 地址,并确保没有路由器或防火墙阻止所考虑端口上的流量。

You need to make sure that each machine knows about the other's private IP address on the LAN (see the ipconfig or ifconfig command). It changes (nearly) each time the devices are connected on the LAN, and sometimes even while they are connected on the LAN.

www.whatismyip.com won't help you, because it will only give you the public IP address of the router/NAT which is closest to that server. There is no guarantee it is also the closest one to your devices. Even if it were, this information would be useless, because you (most often) can't predict how the NAT will translate your private IP address into public IP address.

Even if you could 'guess' that information, there is a possibility that the router/NAT might not let you use this translation behind it (i.e., on the LAN).

To summarize it, make sure you use the proper private IP addresses assigned to your devices and make sure that no router or firewall is blocking traffic over the considered port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文