[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports
[vb2008] applications  ports [vb2008] applications  ports
[vb2008] applications  ports
Go Back  Xtreme Visual Basic Talk > > > [vb2008] applications ports


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2009, 04:19 AM
phil2000 phil2000 is offline
Freshman
 
Join Date: Jan 2006
Posts: 43
Default [vb2008] applications ports


if I run a multiplayer game that sends / receive data from the web, it opens a random port on the PC, to make it job: is possible, by VB.net code, to know what is the specific port opened from the game ?

ty
Reply With Quote
  #2  
Old 05-13-2009, 09:31 AM
Qua's Avatar
Qua[vb2008] applications  ports Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

It is very doubtful that the game will open a random port on your computer. Which game are we talking about? Most game comes with a single port being used, or perhaps more commonly a range of ports being used to communicate.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 05-13-2009, 11:42 AM
phil2000 phil2000 is offline
Freshman
 
Join Date: Jan 2006
Posts: 43
Default

the GAME SERVERS of the several games have a fixed short range of ports...

http://www.nerdclub.net/alp/cowiki/17.html

but the port opened on the Client PC when you run the game is absolutely random...

so the question is: I know the name of the game process .exe file... starting from this data how to discover the port that the executable opens?
Reply With Quote
  #4  
Old 05-13-2009, 02:02 PM
Qua's Avatar
Qua[vb2008] applications  ports Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Since you know the name of the process under observance, you can find the process ID for this application when it is running. You can then use the netstat command which can give you a complete list of active connections and the process ID of the application using the ports. You can then parse this data, matching the process ID to a specific port. I don't find this very elegant, but I'm not aware of other ways of doing this.
__________________
Reading is the foundation for all knowledge - Unknown.

Last edited by Qua; 05-13-2009 at 02:09 PM.
Reply With Quote
  #5  
Old 05-13-2009, 03:46 PM
phil2000 phil2000 is offline
Freshman
 
Join Date: Jan 2006
Posts: 43
Default

you intend the netstat command of the Windows cmd.exe program???

well, with the

netstat -a -b -p udp

command I can see my game executable and the relative ports

now the question is really this: what is the VB.NET equivalent of the netstat -a -b -p udp command?

I can't believe that with the power of the Framework is not possible to obtain in VB.NET, with some lines of code, the same results of the netstat command
Reply With Quote
  #6  
Old 05-13-2009, 04:52 PM
Qua's Avatar
Qua[vb2008] applications  ports Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

There is not functionality for that built into the .NET framework. You can find open source assemblies that does this for you, but using netstat is by far the simpliest. If you wanted to do this yourself, you would have to manually retrieve the TCP- and UDP tables via the IpHelper library, IPHlpApi.dll, which presents a lot of monkeywork.

You can find information about the IpHelper here or you can take a look at various wrappers.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #7  
Old 05-14-2009, 05:49 AM
phil2000 phil2000 is offline
Freshman
 
Join Date: Jan 2006
Posts: 43
Default

ty Qua

all the exemples (even those in MSDN) are in C and not in VB (why??), but I will try to understand something about the IpHelper dll

with this code:
Proc.StartInfo.FileName = "netstat.exe"
Proc.StartInfo.Arguments = "-abp udp"
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.RedirectStandardOutput = True
Proc.StartInfo.CreateNoWindow = True
Proc.Start()
VarTesto = Proc.StandardOutput.ReadToEnd.ToString

and parsing VarTesto I can obtain the Ports opened fron the executable, but like you sayd, I don't find elegant this solution

Last edited by phil2000; 05-14-2009 at 05:56 AM.
Reply With Quote
  #8  
Old 05-14-2009, 05:17 PM
Qua's Avatar
Qua[vb2008] applications  ports Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

While the solution is not very elegant, it is fast and easy to implement and I believe that both unix/mac has the netstat command as well which makes it crossplatform as well. Since you properly only need to check the port number once everytime you open the game, then there is no problem performance wise, so if I were coding this I wouldn't bother using Ip Helper.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports [vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports [vb2008] applications  ports
[vb2008] applications  ports
[vb2008] applications  ports
 
[vb2008] applications  ports
[vb2008] applications  ports
 
-->