/* A "not so good" macro to scan udp ports Usage: psu " */ parse arg host low hi . if ~show("L","rxsocket.library") then if ~addLib("rxsocket.library",0,-30) then do say "can't find rxsocket.library" exit end /* Arguments controll */ if host=="" | host== "?" | low=="" | hi=="" then do say "Usage: psu " exit end if ~DataType(low,NUM) then do say "psu: bad number fromPort" exit end if ~DataType(hi,NUM) then do say "psu: bad number toPort" exit end if hi" exit end /* socket to send an empty message to test ports */ sock = socket("INET","DGRAM","IP") if sock<0 then do say "psu: no DGRAM socket (" || errno() || ")" exit end /* socket to receive ICMP packet from stack */ rsock = socket("INET","RAW","ICMP") if rsock<0 then do say "psu: no ICMP socket (" || errno() || ")" exit end maxRetry = 7 sin.ADDRFAMILY = "INET" do sin.ADDRPORT = low to hi /* We try maxRetry times */ /* If no ICMP_UNREACH/ICMP_UNREACH_PORT we suppose the port is open */ retry = 0 stop = 0 do while (retry=maxRetry then do if GetServByPort("SERV",sin.ADDRPORT,"tcp") then say "psu: servizio" serv.servname "(" || sin.ADDRPORT ||")" "aperto" else say "psu: porta" sin.ADDRPORT "aperta" end end