09-28-2011 10:10 PM
Dear all
i saw a function in TCP library that can get the host address. but do somebody now how to get the default gateway address ?
e.g
IP 192.168.0.4 ( this ip can obtain by get host address function )
subnet 255.255.255.0
deault gateway 192.168.0.1
B.R
Gerry
Solved! Go to Solution.
10-07-2011 03:00 PM
Hey Gerry -
To get the default gateway, you'll want to use the Win32 IP Helper API. Unfortunately, this portion of the Win32 API is only available to users of the Full LabWindows/CVI package.
To retrive IPV4 information about your network adapters, you can use the function GetAdaptersInfo. If you need IPV6 information, you'll need to use GetAdaptersAddresses. I wrote a quick example of using GetAdaptersInfo and attached it, you can see the output below:
Let me know if you have any questions -
NickB
National Instruments
10-07-2011 11:37 PM
10-08-2011 07:58 AM - edited 10-08-2011 08:08 AM
Hi,Gerry:
Maybe, in LabVIEW,there is one way to get all the Internet Information of your local machine, in which system exec.vi is used.
In procedure, select Connectivity->Libraries & Executables->system exec in the Block Diagram.
Connect 'cmd/c ipconfig' to the Command line input, and final indicator output will show all the Internet Information of Local machine.
In the next step, you could select information you want for the output,such as gateway addr.
So, if you could call DOS cmd in labWindows/CVI, the Gateway addr can be obtained in the fimiliar way metioned above.
See the attachment for details for LabVIEW.
10-08-2011 08:00 AM
How about system exec.vi ?
Maybe it could work....
10-08-2011 08:53 PM
Hi, RyanWhite
Thanks for you info , indeed. in CVI , there also a System command availabe to let you able to run the DOS command.
however, in my understanding ipconfig will only print the Network info into standard i/0. but i need those information in my code.
B.R
Gerry
10-09-2011 03:38 PM
It can be a little bit rude, but command output can be redirected to a file by means of '>>' operator. Next you can read back file content.
In Gerry case, "ipconfig >> output.txt" produces a text file which includes among all the default gateway IP. This instruction can be executed in CVI with System () command.
Nevertheless, in my opinion Nick way is far better than this: the only case in which I would suggest Gerry to use the redirection method is if he hasn't Full CVI in his machine.
10-10-2011 02:32 AM
Thanks Roberto
although i have implemented solution from Nick but also nice to know another way. in face the >> symbol is quite new for me 🙂
10-10-2011 09:24 AM
This is a small tip from the good old DOS days, when some little trick helped you a lot in everyday tasks
02-16-2015 09:23 AM - edited 02-16-2015 09:24 AM
Nick, Thank you for this helpful info. I am implementing this 4 years later and the GetAdaptersInfo was not working for me for some reason. A lot can chage in windows in 4 years so I pursued using the GetAdaptersAddresses function instead. It took longer than I care to admit, but I thought I would share the code since in my opinion it should be part of the GetAllTCPHostAddresses function. The main functionality I was after is the first function in the file, which is to find which interface IP on the host is in the same subnet as the provided address. In the process I created a function to list all adapters, prefix addresses, gateways, and the number of mask bits for each interface. I combined some data from header files all into the C file so it seems cluttered, but its all self contained. This will still require the WIN32 API to compile so you'll need the Full CVI package. Hopefully this is some assistance to someone.