简体   繁体   English

ping网络上的计算机

[英]Pinging computers on a network

I am a researcher at University and I'm trying my hand at a bit of amateur java2 programming. 我是大学的一名研究员,正在尝试一些业余的Java2编程。

I've been working through the KnockKnockServer/Client Java2 tutorial to send strings from one program to another using Java Sockets. 我一直在研究KnockKnockServer / Client Java2教程,以使用Java套接字将字符串从一个程序发送到另一个程序。

http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html 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. 完整的源代码可以在此处下载,并且可以很好地编译,并且是使用IP来使两个程序在Java中相互通信的一个很好的例子。

This works fine when I use both the server and the client running on the same machine and the machine name as "localhost" 当我同时使用在同一台计算机上运行的服务器和客户端并且计算机名称为“ localhost”时,此方法可以正常工作

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

And it also works at home when I use it on my home network with a InetAddress: 当我在具有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. 我什至不知道如何让他们互相ping通。 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. 我已经访问了“ www.whatismyip.com”以获取每台计算机的外部ip,但这是行不通的,并且我查看了下一个工作适配器ip及其所处的网关,但仍然无法获得它们互相交谈。

Any ideas. 有任何想法吗。

Thanks! 谢谢!

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

Even i cannot ping two machines at my work place. 即使我不能在工作场所对两台机器执行ping操作。

you need to change the network preferences or try the following: 您需要更改网络偏好设置或尝试以下操作:
(instructions for IE) Go to tools-> internet options -> lan settings -> advanced. (有关IE的说明)转到工具-> Internet选项->局域网设置->高级。
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. 输入网络ip的起始编号,例如,如果您的网络具有以10开头的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). 您需要确保每台计算机都知道对方在LAN上的私有IP地址(请参阅ipconfig或ifconfig命令)。 It changes (nearly) each time the devices are connected on the LAN, and sometimes even while they are connected on the LAN. 每次在LAN上连接设备时(几乎是有时)即使在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. www.whatismyip.com不会为您提供帮助,因为它只会为您提供最接近该服务器的路由器/ NAT的公共IP地址。 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. 即使是这样,该信息也将是无用的,因为您(通常)无法预测NAT如何将您的私有IP地址转换为公共IP地址。

Even if you could 'guess' that information, there is a possibility that the router/NAT might not let you use this translation behind it (ie, on the LAN). 即使您可以“猜测”该信息,路由器/ NAT也可能不允许您在其后面(即,在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. 概括起来,请确保使用分配给设备的正确专用IP地址,并确保没有路由器或防火墙阻止在所考虑端口上的通信。

There are several different parts to this problem: 此问题有几个不同的部分:

1) Can the two machines connect to each other? 1)两台机器可以互相连接吗?

You can test this from the command line with the "ping" command which is available in both Windows and *nix. 您可以在Windows和* nix中使用“ ping”命令从命令行进行测试。 Ping tests for the existence and reliability of a connection to the named machine. Ping测试与指定机器的连接的存在性和可靠性。

2) Could the route be filtered? 2)可以过滤路由吗?

Just because you can ping a machine, doesn't mean there is no firewall or proxy between them. 仅因为您可以ping通计算机,并不意味着它们之间没有防火墙或代理。 You can find the route taken between the two machines with the "tracert" command. 您可以使用“ tracert”命令找到两台机器之间的路由。 The more steps in the route, the more things that might stop your signal 路线中的步骤越多,可能会阻止您的信号越多

3) Is Java firewalled? 3)Java防火墙了吗?

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. 尝试获取一些URL或类似的URL,以查看Java是否具有网络连接。

4) Is the port blocked? 4)端口是否被阻塞?

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. 如果是前者,Java将无法将Socket附加到端口。 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. 没有什么可以阻止您同时运行10000个客户端并查看是否可以连接到其中任何一个客户端。

5) How do you do this in Java? 5)您如何用Java做到这一点?

Ping can be implemented by InetAddress.isReachable(). 可以通过InetAddress.isReachable()实现Ping。

6) What should I say to the angry Network Admin guy who has just turned up? 6)我应该对刚刚出现的生气的网络管理员说些什么?

"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. 一些工作场所具有自动工具来检查它,并将其视为不合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java测试网络上的多台计算机 - Java test multiple computers on a network 开发用于网络中计算机之间通信的应用程序 - Developing an application for communication between computers in a network 使用Java与本地网络外部的计算机连接 - Connecting with computers outside the local network in Java 通过android java检测网络上连接的计算机 - Detect computers connected on network via android java 连接两台计算机(通过无线网络的机器) - Connecting two computers(machines over a wireless network) 如何使用Java中的聊天应用程序连接网络上的两台不同的计算机? - How to connect 2 different computers on a network using a chat application in Java? 多个节点(网络上的计算机)支持的Java(强制应用程序) - Java (Brute-Force Application) supported by multiple Nodes (Computers on network) 将WebLogic实例发布到同一wifi网络和/或Internet中的其他计算机 - Publish WebLogic instance to other computers in the same wifi network and/or internet 在不同网络上的两台计算机之间(通过Internet)发送数据 - sending data between two computers on different network(over the internet) 使用Java中的SNMP查找网络中计算机的登录名 - Find the login name of the computers in the network using SNMP in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM