以下のPythonコードでTCP/IP通信を行おうとしているのですが、特定のソフトウェアとの通信がうまくいきません。
noLoopBack.py
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('192.168.1.5', 49985))
s.sendall(b'testSend')
エラー内容は以下のようなものです。
ConnectionRefusedError: [WinError 10061] 対象のコンピューターによって拒否されたため、接続できませんでした。
しかし、殆ど同じコードでループバックアドレス(127.0.0.1)に対して送信すると特定のソフトウェアとも通信がうまくいきます。
loopBack.py
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('127.0.0.1', 49985))
s.sendall(b'testSend')
ファイアウォールの設定はネットの記事等を参考にして一時的に無効にしてみたのですが、変化がありませんでした。
また、Python単体で作成したTCP/IPサーバーのコードでは192.168.1.5と127.0.0.1共に受信が出来ております。
私の使用している特定のソフトウェアのみで受信ができないという問題が起きるようです。
受信に使用したTCP/IPサーバーのコード
tcpServer.py
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 49985))
s.listen(1)
while True:
conn, addr = s.accept()
with conn:
while True:
data = conn.recv(1024)
if not data:
break
print(data.decode('utf-8'))
このような場合、ファイアウォールによって通信がブロックされている以外に何か考えられる原因がありますでしょうか?
もし、ファイアウォールによってブロックされている場合、どのような方法でブロックを解除できますでしょうか?
追記:netstat -an の結果は以下のようになっていました。
アクティブな接続
プロトコル ローカル アドレス 外部アドレス 状態
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:1714 0.0.0.0:0 LISTENING
TCP 0.0.0.0:1715 0.0.0.0:0 LISTENING
TCP 0.0.0.0:1947 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5040 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
TCP 0.0.0.0:7680 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49664 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49665 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49666 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49667 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49675 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49694 0.0.0.0:0 LISTENING
TCP 0.0.0.0:63939 0.0.0.0:0 LISTENING
TCP 127.0.0.1:5354 0.0.0.0:0 LISTENING
TCP 127.0.0.1:5354 127.0.0.1:49771 ESTABLISHED
TCP 127.0.0.1:5354 127.0.0.1:49772 ESTABLISHED
TCP 127.0.0.1:5939 0.0.0.0:0 LISTENING
TCP 127.0.0.1:6463 0.0.0.0:0 LISTENING
TCP 127.0.0.1:7500 0.0.0.0:0 LISTENING
TCP 127.0.0.1:7501 0.0.0.0:0 LISTENING
TCP 127.0.0.1:15292 0.0.0.0:0 LISTENING
TCP 127.0.0.1:15393 0.0.0.0:0 LISTENING
TCP 127.0.0.1:16494 0.0.0.0:0 LISTENING
TCP 127.0.0.1:27015 0.0.0.0:0 LISTENING
TCP 127.0.0.1:30000 0.0.0.0:0 LISTENING
TCP 127.0.0.1:45623 0.0.0.0:0 LISTENING
TCP 127.0.0.1:49309 127.0.0.1:53527 ESTABLISHED
TCP 127.0.0.1:49310 127.0.0.1:53527 ESTABLISHED
TCP 127.0.0.1:49313 127.0.0.1:64824 ESTABLISHED
TCP 127.0.0.1:49349 127.0.0.1:64824 ESTABLISHED
TCP 127.0.0.1:49771 127.0.0.1:5354 ESTABLISHED
TCP 127.0.0.1:49772 127.0.0.1:5354 ESTABLISHED
TCP 127.0.0.1:49806 127.0.0.1:62522 ESTABLISHED
TCP 127.0.0.1:49985 0.0.0.0:0 LISTENING
TCP 127.0.0.1:50007 0.0.0.0:0 LISTENING
TCP 127.0.0.1:50050 0.0.0.0:0 LISTENING
TCP 127.0.0.1:50053 0.0.0.0:0 LISTENING
TCP 127.0.0.1:50053 127.0.0.1:62235 ESTABLISHED
TCP 127.0.0.1:50054 0.0.0.0:0 LISTENING
TCP 127.0.0.1:53527 0.0.0.0:0 LISTENING
TCP 127.0.0.1:53527 127.0.0.1:49309 ESTABLISHED
TCP 127.0.0.1:53527 127.0.0.1:49310 ESTABLISHED
TCP 127.0.0.1:53527 127.0.0.1:61159 ESTABLISHED
TCP 127.0.0.1:53527 127.0.0.1:61160 ESTABLISHED
TCP 127.0.0.1:61159 127.0.0.1:53527 ESTABLISHED
TCP 127.0.0.1:61160 127.0.0.1:53527 ESTABLISHED
TCP 127.0.0.1:61162 127.0.0.1:64824 ESTABLISHED
TCP 127.0.0.1:61309 127.0.0.1:50001 TIME_WAIT
TCP 127.0.0.1:62235 127.0.0.1:50053 ESTABLISHED
TCP 127.0.0.1:62522 0.0.0.0:0 LISTENING
TCP 127.0.0.1:62522 127.0.0.1:49806 ESTABLISHED
TCP 127.0.0.1:64823 0.0.0.0:0 LISTENING
TCP 127.0.0.1:64824 0.0.0.0:0 LISTENING
TCP 127.0.0.1:64824 127.0.0.1:49313 ESTABLISHED
TCP 127.0.0.1:64824 127.0.0.1:49349 ESTABLISHED
TCP 127.0.0.1:64824 127.0.0.1:61162 ESTABLISHED
TCP 192.168.1.5:139 0.0.0.0:0 LISTENING
TCP 192.168.1.5:52125 13.112.39.59:443 ESTABLISHED
TCP 192.168.1.5:52366 3.216.58.47:443 ESTABLISHED
TCP 192.168.1.5:58122 52.219.68.189:443 CLOSE_WAIT
TCP 192.168.1.5:60282 13.94.40.40:443 ESTABLISHED
TCP 192.168.1.5:60678 162.159.130.234:443 ESTABLISHED
TCP 192.168.1.5:60894 52.149.21.60:443 ESTABLISHED
TCP 192.168.1.5:61248 151.101.129.69:443 ESTABLISHED
TCP 192.168.1.5:61250 104.118.66.103:443 ESTABLISHED
TCP 192.168.1.5:61257 104.16.24.34:443 ESTABLISHED
TCP 192.168.1.5:61282 23.46.129.120:443 ESTABLISHED
TCP 192.168.1.5:61285 198.252.206.25:443 ESTABLISHED
TCP 192.168.1.5:61294 198.252.206.25:443 ESTABLISHED
TCP 192.168.1.5:61307 192.168.1.1:51234 TIME_WAIT
TCP 192.168.1.5:61308 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61310 54.236.127.150:443 CLOSE_WAIT
TCP 192.168.1.5:61311 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61317 192.168.1.1:51236 TIME_WAIT
TCP 192.168.1.5:61319 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61320 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61321 192.168.1.1:51235 TIME_WAIT
TCP 192.168.1.5:61322 13.76.217.211:443 ESTABLISHED
TCP 192.168.1.5:61324 192.168.1.1:51234 TIME_WAIT
TCP 192.168.1.5:61325 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61326 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61329 13.107.18.254:443 ESTABLISHED
TCP 192.168.1.5:61332 204.79.197.222:443 ESTABLISHED
TCP 192.168.1.5:61333 192.168.1.1:51235 TIME_WAIT
TCP 192.168.1.5:61334 192.168.1.1:51234 TIME_WAIT
TCP 192.168.1.5:61340 202.218.175.136:80 TIME_WAIT
TCP 192.168.1.5:61342 192.168.1.1:51235 TIME_WAIT
TCP 192.168.1.5:62228 40.119.211.203:443 ESTABLISHED
TCP 192.168.1.5:62239 52.149.21.60:443 ESTABLISHED
TCP 192.168.1.5:62253 52.204.144.45:443 ESTABLISHED
TCP 192.168.1.5:62954 40.119.211.203:443 ESTABLISHED
TCP 192.168.1.5:65394 122.215.212.9:443 ESTABLISHED
TCP [::]:135 [::]:0 LISTENING
TCP [::]:445 [::]:0 LISTENING
TCP [::]:1947 [::]:0 LISTENING
TCP [::]:5357 [::]:0 LISTENING
TCP [::]:7680 [::]:0 LISTENING
TCP [::]:49664 [::]:0 LISTENING
TCP [::]:49665 [::]:0 LISTENING
TCP [::]:49666 [::]:0 LISTENING
TCP [::]:49667 [::]:0 LISTENING
TCP [::]:49675 [::]:0 LISTENING
TCP [::]:49694 [::]:0 LISTENING
TCP [::]:63939 [::]:0 LISTENING
TCP [::1]:49346 [::]:0 LISTENING
TCP [::1]:61185 [::]:0 LISTENING
TCP [2400:4050:a561:d900:64f5:d8cb:8fd2:2ded]:54015 [2404:6800:4004:808::200d]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:64f5:d8cb:8fd2:2ded]:62233 [2404:6800:4004:81d::200a]:443 ESTABLISHED
TCP [2400:4050:a561:d900:64f5:d8cb:8fd2:2ded]:62236 [2404:6800:4008:c07::bc]:443 ESTABLISHED
TCP [2400:4050:a561:d900:64f5:d8cb:8fd2:2ded]:64036 [2404:6800:4004:80e::200d]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a435:a897:2909:6064]:49790 [2404:6800:4004:81c::200a]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:52365 [2600:140b:a000:196::57]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:53107 [2404:6800:4004:81d::200a]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:53113 [2404:6800:4004:81d::200a]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:53422 [2607:5300:60:1567:a585:cd28:2747:ec5a]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:57609 [2404:6800:4004:80a::200a]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:57610 [2404:6800:4004:800::200d]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:60927 [2606:4700::6812:e48]:443 CLOSE_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61249 [2a04:fa87:fffe::c000:4902]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61252 [2620:116:800e:21:b25f:f2c2:3600:d81a]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61253 [2404:6800:4004:81c::2001]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61259 [2404:6800:4004:81d::2001]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61295 [2404:6800:4004:809::2001]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61312 [2404:6800:4004:819::200d]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61313 [2404:6800:4004:81f::200e]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61314 [2404:6800:4004:81f::200e]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61315 [2404:6800:4004:81f::200e]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61323 [2606:2800:147:ff8:129b:22eb:20b:1347]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61327 [2620:1ec:c11::200]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61328 [2603:1046:c0a:1835::2]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61330 [2620:1ec:bdf::254]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61331 [2620:1ec:bdf::10]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61336 [2404:6800:4004:807::200a]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61337 [2404:6800:4004:80e::200d]:443 ESTABLISHED
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61338 [2404:6800:4004:81f::200a]:443 TIME_WAIT
TCP [2400:4050:a561:d900:a803:f22c:5ac1:83fd]:61339 [2404:6800:4004:807::200a]:443 ESTABLISHED
UDP 0.0.0.0:500 *:*
UDP 0.0.0.0:1947 *:*
UDP 0.0.0.0:3702 *:*
UDP 0.0.0.0:3702 *:*
UDP 0.0.0.0:3702 *:*
UDP 0.0.0.0:3702 *:*
UDP 0.0.0.0:4500 *:*
UDP 0.0.0.0:5050 *:*
UDP 0.0.0.0:5353 *:*
UDP 0.0.0.0:5353 *:*
UDP 0.0.0.0:5353 *:*
UDP 0.0.0.0:5353 *:*
UDP 0.0.0.0:5353 *:*
UDP 0.0.0.0:5355 *:*
UDP 0.0.0.0:6666 *:*
UDP 0.0.0.0:50728 *:*
UDP 0.0.0.0:52940 *:*
UDP 0.0.0.0:52941 *:*
UDP 0.0.0.0:52943 *:*
UDP 0.0.0.0:57617 *:*
UDP 0.0.0.0:61684 *:*
UDP 0.0.0.0:62000 *:*
UDP 0.0.0.0:63546 *:*
UDP 0.0.0.0:63555 *:*
UDP 0.0.0.0:63557 *:*
UDP 0.0.0.0:63558 *:*
UDP 0.0.0.0:63559 *:*
UDP 0.0.0.0:63560 *:*
UDP 0.0.0.0:63561 *:*
UDP 0.0.0.0:63562 *:*
UDP 0.0.0.0:64187 *:*
UDP 127.0.0.1:1900 *:*
UDP 127.0.0.1:55016 *:*
UDP 127.0.0.1:56827 *:*
UDP 127.0.0.1:56828 *:*
UDP 127.0.0.1:63554 *:*
UDP 192.168.1.5:137 *:*
UDP 192.168.1.5:138 *:*
UDP 192.168.1.5:1900 *:*
UDP 192.168.1.5:5353 *:*
UDP 192.168.1.5:5353 *:*
UDP 192.168.1.5:55015 *:*
UDP [::]:500 *:*
UDP [::]:1947 *:*
UDP [::]:3702 *:*
UDP [::]:3702 *:*
UDP [::]:3702 *:*
UDP [::]:3702 *:*
UDP [::]:4500 *:*
UDP [::]:5353 *:*
UDP [::]:5353 *:*
UDP [::]:5353 *:*
UDP [::]:5355 *:*
UDP [::]:50728 *:*
UDP [::]:52942 *:*
UDP [::]:57617 *:*
UDP [::]:62001 *:*
UDP [::]:63547 *:*
UDP [::]:63556 *:*
UDP [::]:64187 *:*
UDP [::1]:1900 *:*
UDP [::1]:5353 *:*
UDP [::1]:5353 *:*
UDP [::1]:55014 *:*
UDP [fe80::69d5:b3e3:615f:bd3d%12]:1900 *:*
UDP [fe80::69d5:b3e3:615f:bd3d%12]:55013 *:*