Hey,
How can I tell which ports are in use on the computer my program is running on, without trying to create a server on each one. Also how can I check which ports are in use on a remote computer?
Thanls a lot,
Killswitch
Determine which ports are in use
-
Killswitch
- Enthusiast

- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Determine which ports are in use
~I see one problem with your reasoning: the fact is thats not a chicken~
-
Killswitch
- Enthusiast

- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Have a bit of patience, you don't need to bump after one single day... :roll:
A web search for "vb check open ports" and you'll see many Visual Basic
examples which should be easy to convert to PureBasic. Indeed, the first
Google match leads to this page...
http://vbforums.com/showthread.php?p=21 ... ost2137718
...which explains that executing a redirected NetStat command to a file will
create a list that you can parse. So here's a working procedure for you:
A web search for "vb check open ports" and you'll see many Visual Basic
examples which should be easy to convert to PureBasic. Indeed, the first
Google match leads to this page...
http://vbforums.com/showthread.php?p=21 ... ost2137718
...which explains that executing a redirected NetStat command to a file will
create a list that you can parse. So here's a working procedure for you:
Code: Select all
Procedure SaveActivePorts(file$)
a$=Space(255)
If OSVersion()<#PB_OS_Windows_2000
GetWindowsDirectory_(a$,255)
Else
GetSystemDirectory_(a$,255)
EndIf
c$=Space(255) : GetEnvironmentVariable_("comspec",@c$,255)
RunProgram(c$,"/c "+a$+"\netstat.exe -a -n > "+Chr(34)+file$+Chr(34),"",1|2)
EndProcedure
SaveActivePorts("c:\Ports.txt")
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
Killswitch
- Enthusiast

- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Nuts I didn't want to use the netstat command, that's how i've done this in the past. I was hoping for a API command or something similar. Sorry about the bump, but on my computer the thread was slipping down the page and I am a bit eger for a solution.
~I see one problem with your reasoning: the fact is thats not a chicken~
-
Killswitch
- Enthusiast

- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
To be honest it feels like cheating. If you use a batch file then you're basically making something else do all the mokey work - I kinda like the idea of writing it all myself. Then again I suppose you could pretty much say the same for an API command.
Still are there any other solutions?
Still are there any other solutions?
~I see one problem with your reasoning: the fact is thats not a chicken~
just try to bind one, if you cannot it is in use 
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
Killswitch
- Enthusiast

- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Does this help (GetTcpTable_() and GetUdpTable_() in particular)?
http://www.codeproject.com/internet/tcpinfo.asp
http://www.codeproject.com/internet/tcpinfo.asp
Mat
