473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to check the Ports Status on a remote server using VB Script

Hello Friends,

Can any body help me out in "how to check the Ports Status (opened & enabled) on a remote server using VB Script

Any sort of help is highly appreciable.....

Thnx

-FH
Nov 15 '07 #1
20 47030
AHMEDYO
112 100+
hi

i think this code work well but it have loop to check for state that i cant accept but im not good in vbs and in same time i think we cant do other thing because we cant receve events in vbs

' VBScript source code

Function CheckPort(Byval Server,Byval Port)
Dim SockObject
set SockObject=CreateObject("MSWinsock.Winsock.1")
SockObject.Protocol=0 ' TCP
Call SockObject.Close
Call SockObject.Connect (Server,Port)
while ((SockObject.State=6) or (SockObject.State=3)) 'socket state <> connecting or connection pending
'do nothing
wend
if(SockObject.State=7) then ' if socket connected
msgbox "Port OPen"
elseif(SockObject.State=9)then' If Error
msgbox "error"
elseif(SockObject.State=0)then 'Closed
msgbox "connection refused"
end if
call SockObject.Close
set SockObject=nothing
End Function
Call CheckPort("Server",445)

and plz take in ur mind Winsock COM Class is only installed with vb6 component and u will not find it in PC that not have vb6 components

Best Regards
Nov 15 '07 #2
Thanks Ahmed,

The logic is exactly what Iwant but I think this will not completely solve my problem, I need to install VB6 on all my target or remote servers on which I need to run this code (and this I cannot do), anyways I am getting this errror

Microsoft VBScript runtime error: ActiveX component can't create object: 'MSWinsock.Winsock.1'

is there any other way to get this info

Thnx a million

FH
Nov 15 '07 #3
Ahmed,

More over, I have this code, but this is limited to check the ports' status on local machine, cannot be executed on a remote server

################ CODE ##################

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set colPorts = objPolicy.GloballyOpenPorts

For Each objPort in colPorts
Wscript.Echo "Port name: " & objPort.Name
Wscript.Echo "Port number: " & objPort.Port
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port enabled: " & objPort.Enabled
Next
Nov 15 '07 #4
AHMEDYO
112 100+
Ahmed,

More over, I have this code, but this is limited to check the ports' status on local machine, cannot be executed on a remote server

################ CODE ##################

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set colPorts = objPolicy.GloballyOpenPorts

For Each objPort in colPorts
Wscript.Echo "Port name: " & objPort.Name
Wscript.Echo "Port number: " & objPort.Port
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port enabled: " & objPort.Enabled
Next
yas man u wanna enumerate Open Ports but i was give u port scanner , sorry :D , because u dont wanna external component and u wanna to get ports from remote server , i think and not sure may be using WMI winmgmts Class , but it have heavy number of classes and i must take a look, and i will response
Nov 15 '07 #5
AHMEDYO
112 100+
Thanks Ahmed,

The logic is exactly what Iwant but I think this will not completely solve my problem, I need to install VB6 on all my target or remote servers on which I need to run this code (and this I cannot do), anyways I am getting this errror

Microsoft VBScript runtime error: ActiveX component can't create object: 'MSWinsock.Winsock.1'

is there any other way to get this info

Thnx a million

FH
:D as i said u dont have MSWinsockLib in ur machine , u must install it
Nov 15 '07 #6
I installed it, but still getting the same error, any help using Win32_ classes or any other you know from which I can get the ports info using VBScript
Nov 16 '07 #7
AHMEDYO
112 100+
I installed it, but still getting the same error, any help using Win32_ classes or any other you know from which I can get the ports info using VBScript
which file you installed?, and how u install it????
the file name is MSWINSCK.OCX
after you copy it you must registry it

by the way, try to change the socket number or remove it in the current line

Expand|Select|Wrap|Line Numbers
  1. set SockObject=CreateObject("MSWinsock.Winsock.1")
or use "Regedit" search the registry about ".Winsock" to see what version you install

and i will search about Winmgmts Win32_Classes and i will reply

GOOD LUCK
Nov 16 '07 #8
Thnks Ahmed I have searched almost all of the Win32_ classes, couldn't find any helpful, s stated earlier the below is only gathering the ports info on the local pc, not sure where to give the remote server name as input in it

Any idea how to run this code on a remote server?

################ CODE ##################

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set colPorts = objPolicy.GloballyOpenPorts

For Each objPort in colPorts
Wscript.Echo "Port name: " & objPort.Name
Wscript.Echo "Port number: " & objPort.Port
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port enabled: " & objPort.Enabled
Next
##########################################

I am just searching for an option that could be available for "LocalPolicy" in the "Set objPolicy = objFirewall.LocalPolicy.CurrentProfile", tried alot but of no luck................any sort of help will be highly appreciable.....

Regards
Nov 16 '07 #9
Thanks a million for ur patience......Awaiting for ur valuable reply...:)
Nov 16 '07 #10
AHMEDYO
112 100+
Thanks a million for ur patience......Awaiting for ur valuable reply...:)
Many Thanx man, i am trying, searching and thinking, i think i will got it
:D

Regards...
Nov 16 '07 #11
Any luck Ahmed.... ???

thnx
Nov 19 '07 #12
Awaiting for ur valuable reply Ahmed........

thnx a million
Nov 20 '07 #13
AHMEDYO
112 100+
Hey..

i wanna ask a question because i think there is no way to check about open ports except scanning as i was post to you the first script

the question is , this script will run within domain??, have active directory??, if so, i think we have two ways to do that.

first distribute MSWinsock Library in your server then we can use it AS DCOM from any PC within domain

second,we can copy MSWinsock.ocx to \\Domain.Com\Sysvol shared (and almost all users have permission to access this folder to access policy) folder and then improve the first script to check if Winsock found in current machine or not , if not it will copy the MSWinsock .OCX file to system32 folder and registry it and then we can use Winsock Object

Waiting your reply

Best Regards.
Nov 20 '07 #14
We dont have an AD, is there any way from which we can get ports info from server's registry entry??

thnx
Nov 21 '07 #15
AHMEDYO
112 100+
answer is No..

Bet Regards
Nov 21 '07 #16
AHMEDYO
112 100+
HI..

but i could be wrong , i think that answer is no, because the listining ports is open by the running process at runtime and no process is registry each port in registry, all i was know thats OS have TCP table and UDP table and all of these tables stored in memory not in registry, and you can get it using API call, but from VBscript i dont know where i can get it from, but i think may be there is way to do that from Winmgmts: or RPC i dont know exactly, i am not experienced with them, and i think may be you could get what ports OS services provide from registry as Microsoft-Ds port = "445" from registry Key for example

Expand|Select|Wrap|Line Numbers
  1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters
  2. TransportBindname="\Device\"
  3.  
transportBindname="\Device\" mean that Netbt service will listen at port 445, but i think there is no way to get all listining ports

Thats what i was think

Best Regards
Nov 21 '07 #17
Ahmed,

I have tried with the script you have given, but it is not giving me any result (I can only see a blank out put) nothing is getting retrieved

thnx
Nov 21 '07 #18
I have copied "MSWINSCK.ocx" to C:\WINNT|System32 and also registered it, checked everything is fine, looks like the code needs to be modified, can you please take a loook at your code once again and send me again.

thnx a million for ur patience and support, appreciate you... :)
Nov 21 '07 #19
Ahmed...... I got it this time

slightly modifed your script, removed While and added some other logic...I got it this time............ :)

GR8 THANKS AHMED.......really appreciate your srupport

Call CheckPort(srv_name,77)

Dim SockObject
Function CheckPort(Byval Server,Byval Port)
set SockObject=CreateObject("MSWinsock.Winsock.1")
SockObject.Protocol=0 ' TCP
SockObject.Close
SockObject.Connect Server,port
Wscript.Sleep 50
if(SockObject.State=6) then ' if sockect is attempting to connect i.e
WScript.echo "Invalid Port"
elseif(SockObject.State=7) then ' if socket connected
WScript.echo "Port Open"
elseif(SockObject.State=9)then' If Error
WScript.echo "error"
elseif(SockObject.State=0)then 'Closed
WScript.echo "connection refused"
end if
call SockObject.Close
set SockObject=nothing
End Function
Nov 21 '07 #20
AHMEDYO
112 100+
HI...

Good work Man, its seem pretty nice now :)

Kind Regards
Nov 21 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
1
by: gallaczmit | last post by:
Will this code give me a true view of a computer's status? All I am looking for is to see if the computer is reachable or not. My end goal is to get a list of IP addresses from a MS SQL Server,...
2
by: pratcp | last post by:
I have a remote server (a shared hosting webserver) where I have few users ftp some flat files. I need to access these files using a windows app/windows service written using c# and run it on a...
0
by: Computer geek | last post by:
I am a beginner programmer and would like a little help with a piece of code. Does anyone know how write code that will check the status of a service running on a remote server? Or is it even...
1
by: mdfidahussain | last post by:
Hi Friends, Anyone help me out in getting Ports' status information from the Registry Key? if there is no possibility of getting this info from Registry entry, is there any other way from whic I...
1
by: kriz4321 | last post by:
Hi All, I need to connect to a remote server using perl. The server is SSH enabled and I find it difficult to Install Net::SSH::Perl as it has many modules as prereq. I have Installed NET:Telnet...
0
by: kottiPrasad | last post by:
Hello , I have mailboxes in the exchange server and i need to copy the mailboxes data from the exchange server and place it to the other exchange server using c#.Is it possible to access the...
0
by: laxmimanasa | last post by:
Hi all, I am working with python. I have to write script to open putty and connect to remote server and display the disks details. I used the commans os.popen3("path of putty") to connect to putty...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.