LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

get default gateway address

Solved!
Go to solution

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

0 Kudos
Message 1 of 10
(8,435 Views)
Solution
Accepted by Gerryli

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:

 

ip.png

 

Let me know if you have any questions -

 

NickB

National Instruments

Message 2 of 10
(8,415 Views)
Thanks Nick. in fact I have spent a lot of time in MSDN also try to find out the sloution. but failed. i think i did not go into right cataloge . however, it would be nice if NI could add this function in TCP library. B.R Gerry
0 Kudos
Message 3 of 10
(8,408 Views)

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.

0 Kudos
Message 4 of 10
(8,398 Views)

How about system exec.vi ?

 

Maybe it could work....

0 Kudos
Message 5 of 10
(8,397 Views)

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

0 Kudos
Message 6 of 10
(8,381 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 10
(8,369 Views)

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  🙂

0 Kudos
Message 8 of 10
(8,362 Views)

This is a small tip from the good old DOS days, when some little trick helped you a lot in everyday tasks Smiley Wink



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 10
(8,348 Views)

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.

Message 10 of 10
(7,281 Views)