Sep-28-2018, 03:40 PM
Hello Community,
on a Linux system I try to use nc command within a Python script to check if a UDP port is open or not.
My script:
Can someone please explain why.
Best regards
on a Linux system I try to use nc command within a Python script to check if a UDP port is open or not.
My script:
import os
import re
CHECK = 0
UDPSTATUS = os.popen('nc -vz -u 127.0.0.1 123')
LINE = " "
while LINE:
LINE = UDPSTATUS.read()
print LINE
if LINE.find('succeeded!') != -1:
print " => UDP PORT OK"
CHECK = 1
print CHECK
UDPSTATUS.close()
if CHECK == 0:
print " !!! UDP PORT NOT OK !!!"
print CHECKWhen the NTP service is running I got:Output:Connection to 127.0.0.1 123 port [udp/ntp] succeeded!
!!! UDP PORT NOT OK !!!
0I do not understand why the script does not find "succeeded!".Can someone please explain why.
Best regards
