Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. vector<string> ofApp::getLocalIPs()
  2. {
  3. vector<string> result;
  4.  
  5. #ifdef TARGET_WIN32
  6.  
  7. string commandResult = ofSystem("ipconfig");
  8. //ofLogVerbose() << commandResult;
  9.  
  10. for (int pos = 0; pos >= 0; )
  11. {
  12. pos = commandResult.find("IPv4", pos);
  13.  
  14. if (pos >= 0)
  15. {
  16. pos = commandResult.find(":", pos) + 2;
  17. int pos2 = commandResult.find("\n", pos);
  18.  
  19. string ip = commandResult.substr(pos, pos2 - pos);
  20.  
  21. pos = pos2;
  22.  
  23. if (ip.substr(0, 3) != "127") // let's skip loopback addresses
  24. {
  25. result.push_back(ip);
  26. //ofLogVerbose() << ip;
  27. }
  28. }
  29. }
  30.  
  31. #else
  32.  
  33. string commandResult = ofSystem("ifconfig");
  34.  
  35. for (int pos = 0; pos >= 0; )
  36. {
  37. pos = commandResult.find("inet ", pos);
  38.  
  39. if (pos >= 0)
  40. {
  41. int pos2 = commandResult.find("netmask", pos);
  42.  
  43. string ip = commandResult.substr(pos + 5, pos2 - pos - 6);
  44.  
  45. pos = pos2;
  46.  
  47. if (ip.substr(0, 3) != "127") // let's skip loopback addresses
  48. {
  49. result.push_back(ip);
  50. //ofLogVerbose() << ip;
  51. }
  52. }
  53. }
  54.  
  55. #endif
  56.  
  57. return result;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement