- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
Does anyone know of a neat way to get the IP address of a machine from within a Fortran program? I can spawn a console program to run ipconfig, etc, but that's seems clumsy - I'm surprised there doesn't seem to be a Windows API function for this. Have I missed something?
Many thanks in advance,
Mike
Does anyone know of a neat way to get the IP address of a machine from within a Fortran program? I can spawn a console program to run ipconfig, etc, but that's seems clumsy - I'm surprised there doesn't seem to be a Windows API function for this. Have I missed something?
Many thanks in advance,
Mike
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This MSDN article shows how to do it from VB using the Winsock API. You can probably figure out how to do this in Fortran from the example here.
I note that the gethostbyname function has been superseded by getaddrinfo from WS2_32.lib, but I also note that Intel Fortran doesn't provide an interface to that in module WS2. gethostbyname is in module WSOCK32.
I note that the gethostbyname function has been superseded by getaddrinfo from WS2_32.lib, but I also note that Intel Fortran doesn't provide an interface to that in module WS2. gethostbyname is in module WSOCK32.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks, Steve,
The MSDN article demonstrates how to get all the IP addresses used by the machine "if the machine is multi-homed" (to quote from the article). I have already retrieved that information from reading the registry, but none of it helps me because I need to know the IP address in use at the time the program is being run. If I can get that, I can use it to determine which of many servers to connect to. The logonserver environment variable looked good for a while, but it has proved totally unreliable and is a big disappointment.
Thanks again - and season's greetings from down under,
Mike
The MSDN article demonstrates how to get all the IP addresses used by the machine "if the machine is multi-homed" (to quote from the article). I have already retrieved that information from reading the registry, but none of it helps me because I need to know the IP address in use at the time the program is being run. If I can get that, I can use it to determine which of many servers to connect to. The logonserver environment variable looked good for a while, but it has proved totally unreliable and is a big disappointment.
Thanks again - and season's greetings from down under,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Remember that machines don't have IP addresses - adapters do. There may be multiple IP addresses "in use" at any time, trivially 127.0.0.1 etc, but consider VPN's, multiple network cards, VPN's, IP4/IP6...
What are you trying to do?
If something isn't available in Winsock then there's a lower level IP helper library that gives you equivalent information to ipconfig. I've used it in the past from C to get MAC addresses for ethernet adapters.
What are you trying to do?
If something isn't available in Winsock then there's a lower level IP helper library that gives you equivalent information to ipconfig. I've used it in the past from C to get MAC addresses for ethernet adapters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Guys, that's exactly what I needed.
To answer the question "what am I trying to do?" - there are dozens of servers in my environment spread over an enormous geographical area. Software I develop needs to know where it is being run from in order to connect to the appropriate server. From a list I have been given by our systems people I can work out where the user is located by using the subnet IP address. This system works well when I capture the output from ipconfig and get the information from there, but I hate to see a console window flashing up each time anyone starts a program.
Many thanks again.
Mike
To answer the question "what am I trying to do?" - there are dozens of servers in my environment spread over an enormous geographical area. Software I develop needs to know where it is being run from in order to connect to the appropriate server. From a list I have been given by our systems people I can work out where the user is located by using the subnet IP address. This system works well when I capture the output from ipconfig and get the information from there, but I hate to see a console window flashing up each time anyone starts a program.
Many thanks again.
Mike

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page