我找到了一个非常简单的 python 服务器和客户端的代码。当我第一次运行它时,我在不同终端的同一台机器上运行服务器和客户端,它运行良好。但是现在我在我的树莓派上运行服务器并在我的桌面上运行我的客户端,我得到一个“连接被拒绝的错误。我的直觉告诉我这是防火墙阻止了我正在使用的端口,但我使用了以下命令我发现打开了端口。
sudo iptables -A INPUT -i eth0 -p tcp --sport 4042 -m state --state ESTABLISHED -j ACCEPT
在我的 python 代码中,我的客户端和服务器都连接到这个端口。当我sudo nmap -sS -O 127.0.0.1
在我的 pi 上运行时,我得到以下输出:
Starting Nmap 6.00 ( http://nmap.org ) at 2013-08-29 23:52 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00027s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
3389/tcp open ms-wbt-server
No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=6.00%E=4%D=8/29%OT=22%CT=1%CU=37241%PV=N%DS=0%DC=L%G=Y%TM=521FDEE
OS:0%P=armv7l-unknown-linux-gnueabi)SEQ(SP=103%GCD=1%ISR=105%TI=Z%CI=Z%II=I
OS:%TS=7)OPS(O1=M400CST11NW3%O2=M400CST11NW3%O3=M400CNNT11NW3%O4=M400CST11N
OS:W3%O5=M400CST11NW3%O6=M400CST11)WIN(W1=8000%W2=8000%W3=8000%W4=8000%W5=8
OS:000%W6=8000)ECN(R=Y%DF=Y%T=41%W=8018%O=M400CNNSNW3%CC=Y%Q=)T1(R=Y%DF=Y%T
OS:=41%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=41%W=0%S=A%A=Z%F=R
OS:%O=%RD=0%Q=)T5(R=Y%DF=Y%T=41%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=
OS:41%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=41%W=0%S=Z%A=S+%F=AR%O=%RD=0
OS:%Q=)U1(R=Y%DF=N%T=41%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R
OS:=Y%DFI=N%T=41%CD=S)
Network Distance: 0 hops
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 29.35 seconds
当我跑步时,iptables -L
我得到:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:4042 state ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination