Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<string> ofApp::getLocalIPs()
- {
- vector<string> result;
- #ifdef TARGET_WIN32
- string commandResult = ofSystem("ipconfig");
- //ofLogVerbose() << commandResult;
- for (int pos = 0; pos >= 0; )
- {
- pos = commandResult.find("IPv4", pos);
- if (pos >= 0)
- {
- pos = commandResult.find(":", pos) + 2;
- int pos2 = commandResult.find("\n", pos);
- string ip = commandResult.substr(pos, pos2 - pos);
- pos = pos2;
- if (ip.substr(0, 3) != "127") // let's skip loopback addresses
- {
- result.push_back(ip);
- //ofLogVerbose() << ip;
- }
- }
- }
- #else
- string commandResult = ofSystem("ifconfig");
- for (int pos = 0; pos >= 0; )
- {
- pos = commandResult.find("inet ", pos);
- if (pos >= 0)
- {
- int pos2 = commandResult.find("netmask", pos);
- string ip = commandResult.substr(pos + 5, pos2 - pos - 6);
- pos = pos2;
- if (ip.substr(0, 3) != "127") // let's skip loopback addresses
- {
- result.push_back(ip);
- //ofLogVerbose() << ip;
- }
- }
- }
- #endif
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement