File: scan

package info (click to toggle)
newlisp 10.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 6,248 kB
  • sloc: ansic: 33,280; lisp: 4,181; sh: 609; makefile: 215
file content (48 lines) | stat: -rwxr-xr-x 1,162 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env newlisp

; - scan - v.1.0 port scanner in newLISP
; much faster on Mac OSX, LINUX and other UNIX than on Windows
; as on UNIX net-connect can return on failure before the timeout
; has exspired. On Windows net-connect will wait out the timeout
; if it cannot connect.
;
; Example:
;

(when (< (sys-info -2) 10204)
	(println "newLISP v.10.2.4 or later required")
	(exit))

(set 'host (main-args 2))
(unless host (println [text]
- newLISP scan v1.1, a simple portscanner

USAGE: scan <host-ip-or-name> [<timeout-msec> [<from-port> [<to-port>]]]

EXAMPLES:
   scan localhost 200 1 1024
   scan example.com
   scan 192.168.1.92 300 20

Default for <timeout-msec> is 1000 milli seconds
Defaults for <from-port> and <to-port> are 1 to 1024
[/text])
	(exit))

(set 'timeout (or (int (main-args 3)) 1000))
(set 'from-port (or (int (main-args 4)) 1))
(set 'to-port (or (int (main-args 5)) 1024))

(println "scanning: " host)
(for (port from-port to-port)
	(if (set 'socket (net-connect host port timeout))
		(begin
			(println "open port: " port " " (or (net-service port "tcp") ""))
			(net-close socket))
		(print port "\r"))
)
(println)
(exit)

;; eof