Get local IP address windows?

Is there an equivalent library for listing IP addresses on comm devices for Windows?
Maybe something similar to this:


which uses" #include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>" libraries which are not present in windows.

You could have a look at winsock as described here or poco.
A hacky way would be to parse the result of

auto res = ofSystem("ipconfig"); 

I wrote this a while back - I think it may work on Windows as well

Will also return this data and a lot of other info (including public IP address).

See the example

for more.

I used this one:

ofApp.cpp:

string my_ip; 

void ofApp::setup()
{
    system("ipfirst.cmd");
    ofFile file("my.ip");
    file >> my_ip;
    ofLog() << "My IP: " << my_ip;
}

ipfirst.cmd:

@echo off
rem set ip_address_string="IP Address"
rem Uncomment the following line when using Windows 7 or Windows 8 / 8.1 (with removing "rem")!
set ip_address_string="IPv4 Address"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do (
    echo%%f> data\my.ip
    goto :eof
)
1 Like