Scanned single host single port by VBS written

xiaoxiao2021-03-06  51

Writer: Demonalex

WSH's best interaction I / O method is too msgbox () output and inputbox (), so the vital gods are input in parameters.

Inputbox () function, by using it gets the address and port number of the remote host.

Next is to define the Winsock control object:

Set socket = wscript.createObject ("Mswinsock.winsock", "Winsock_")

'The above sentence means: establishing a Mswinsock.winsock object called Socket and defines the subsequent event call.

'Prefix Winsock_

Set the properties of the object Socket:

Socket.Protocol = 0 '0 is TCP, 1 is UDP

Socket.RemotEport = port number of the remote host is defined as the port number inhaled with inputbox ()

Socket.RemoteHost = host 'The address of the remote host is defined as an address inhaled with inputbox ()

When setting the relevant properties, you can call the connect () method directly:

Socket.connect

The main thread delay is required to wait for Connect () to establish three handshakes. A cycle body can be created here for delays.

For a = 1 to 30 step 1 'circulation 30 times

Wscript.sleep 10 'Every sleep 10

Next 'ends cycle part

In the delay waiting time above, if the connection can be established normally, the MSWinsock control automatically calls the Connect event.

Sub winSock_connect () Event entry, Note: "Event" is the way the subroutine SUB is used, which calls the prefix of the SUB name.

'The prefix established for us when you create an object (the second parameter called)

MsgBox ("The" & socket.remotEport & "IS Opened!") 'prompts that the port is open.

Socket.close 'indicates that the socket object "death"

WScript.quit 'Exit

End Sub 'End Event

If the connection cannot be established after the delay (cannot enter the Connect event), the connection failed in the main thread and closes the program.

Msgbox ("THE" & socket.remotEport & "Is Closed!") 'prompts that the port is not open

Socket.close 'indicates that the socket object "death"

WScript.quit 'Exit

It is more important to be more important, the scope of the variable. Because the variable socket is used to define mswinsock.winsock

Object class carrier, so it must be "role in the main thread and the event, so it must be defined as public global variables.

The entire program is as follows:

Public Socket, A, Host, Port

Host = INPUTBOX ("Host / IP:")

Port = INPUTBOX ("Port:")

Set socket = wscript.createObject ("Mswinsock.winsock", "Winsock_")

Socket.Protocol = 0

Socket.remotEport = port

Socket.remotehost = Host

Socket.connect

For a = 1 to 30 step 1

WScript.sleep 10

NEXT

Msgbox ("THE" & socket.remoteport & "IS closed!") Socket.close

WScript.quit

SUB Winsock_Connect ()

Msgbox ("THE" & socket.remoteport & "IS Opened!")

Socket.close

WScript.quit

End Sub

'Write port scanner written by VBS

Saved as Safer.vbs directly under CMD

转载请注明原文地址:https://www.9cbs.com/read-83173.html

New Post(0)