Mapping the process name to the port number
#1
Posted 23 December 2011 - 12:46 PM
What is the best method to get the VI server port used by any Exe in execution, whose process name is known (How can the process name be mapped to the port number (VI server) used by that process)? We are currently using netstat to find the port number. The iphlpapi.dll system DLL methods also work by getting the entire list of Process ids and ports. But there might be a better method to achieve the same functionality (A method that directly maps the process name to the port without getting a list of all processes and their ports). Is there a better method to get this functionality?
Thank you,
Ganesh Kumar
#2
Posted 23 December 2011 - 04:11 PM
Tim
"If this was easy our kids would be doing it." - Coworker
#3
Posted 23 December 2011 - 04:30 PM
If you have development control of the applications in question, Tim_S's idea is excellent.
#4
Posted 26 December 2011 - 04:48 AM
Tim,You can, when creating a listener, give the port number a string name. The TCP connect primitive can accept the string name as the port number.
Tim
Thank you for your reply. The requirement is, given any Exe name, the VI that we develop must be able find out the port number that the Exe is using. Hence the solution to this problem must be independent of any other appication. The reason why we are looking for the port number is that we need to open the application reference.
V I Engineering, Inc., Thanks for your reply. The option of using iphlpapi.dll may be a good one. But the functions may go unsupported in the newer versions of Windows. For example, AllocateAndGetTcpExTableFromStack method in this DLL is not availalbe from Windows Vista. That is the reason why we will have to re-think.If you've gotten the iphlpapi.dll method working robustly and it works on all the versions of Windows you need, I'd say this is the ideal way.
I have one more question. In case, for an application, if the web server is also enabled, we would get 2 port numbers for the same application (when we try to find the ports used by the application using any method like netstat). Assuming we have no control over the application being developed, how do we find out as to which port corresponds to the Web Server and which one corresponds to VI server?
Thank you,
Ganesh Kumar
Edited by ganeshkumar1989, 26 December 2011 - 04:51 AM.
#5
Posted 27 December 2011 - 02:50 PM
"If this was easy our kids would be doing it." - Coworker
#6
Posted 27 December 2011 - 05:05 PM
I agree with Tim_S. It's unclear to me, though; are you using the Allocate...Stack function or is this just an example of deprecation? If the former, what is Microsoft's official recommendation for its successor? In any case, if all of your functionality works on all the platforms you want to support *right now* then I'd write the code and call it a day. No point in coding circles around a problem which may never come to be.V I Engineering, Inc., Thanks for your reply. The option of using iphlpapi.dll may be a good one. But the functions may go unsupported in the newer versions of Windows. For example, AllocateAndGetTcpExTableFromStack method in this DLL is not availalbe from Windows Vista. That is the reason why we will have to re-think.
To identify a Web Server port, issue a HEAD request and see if you get a valid HTTP response. There may be a built-in way to do this, but this is what came to mind.I have one more question. In case, for an application, if the web server is also enabled, we would get 2 port numbers for the same application (when we try to find the ports used by the application using any method like netstat). Assuming we have no control over the application being developed, how do we find out as to which port corresponds to the Web Server and which one corresponds to VI server?
To identify a VI server, use the Open Application Reference node and see if the node does not return an error. If you cannot test from LabVIEW, I don't know what else you can do.












