Guest User

Untitled

a guest
Feb 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #define SU_WCFG_SERVER_ASYNC
  2.  
  3.  
  4. ........
  5. ........
  6.  
  7. #ifdef SU_WCFG_SERVER_ASYNC
  8. #define SUWebSocketServer AsyncWebSocket
  9. #define SUWebServerRequest AsyncWebServerRequest
  10. #else
  11. ......
  12. #endif
  13.  
  14. extern "C" {
  15. #include "user_interface.h" // Required for some low level wifi functions
  16. }
  17.  
  18. ............
  19. ............
  20.  
  21.  
  22. String suIpAddressToString( IPAddress ipAddress )
  23. {
  24. return String( ipAddress[0] )+"."+
  25. String( ipAddress[1] )+"."+
  26. String( ipAddress[2] )+"."+
  27. String( ipAddress[3] );
  28. }
  29.  
  30. IPAddress suStringToIpAddress( String ipAddress )
  31. {
  32. IPAddress ip = IPAddress( 0, 0, 0, 0 );
  33. char* pStr = (char*)ipAddress.c_str();
  34. uint8_t i = strlen( pStr );
  35. uint8_t iPos = 4;
  36.  
  37. // Test before start
  38. if( i > 6 && pStr[i-1] != '.' )
  39. {
  40. while( i-- && iPos )
  41. {
  42. if( pStr[i] == '.' || i == 0 )
  43. {
  44. ip[--iPos] = String( (char*)&pStr[i+(i>0)] ).toInt();
  45. pStr[i] = 0; // set null termination to truncate
  46. }
  47. }
  48. }
  49.  
  50. return ip;
  51. }
  52.  
  53. String suGetClientIp( SUWebServerRequest* request )
  54. {
  55. if( request )
  56. { return suIpAddressToString( IPAddress( request->client()->remoteIP() )); }
  57.  
  58. return "";
  59. }
  60.  
  61. String suGetClientMacAddress( SUWebServerRequest* request )
  62. {
  63. if( request )
  64. {
  65. struct ip_addr* IPaddress;
  66. IPAddress ip;
  67. struct station_info* stat_info = wifi_softap_get_station_info();
  68. String sClientIp = suGetClientIp( request );
  69.  
  70. Serial.print( "Client ip: " );
  71. Serial.println( sClientIp );
  72.  
  73. if( sClientIp.length() > 0 )
  74. {
  75. while( stat_info )
  76. {
  77. IPaddress = &stat_info->ip;
  78. ip = IPaddress->addr;
  79.  
  80. if( suIpAddressToString( ip ) == sClientIp )
  81. {
  82. // Kind of rude and ugly to exit a loop and function this way
  83. // however it works with less 'check' overhead. OK to me.
  84. return String( stat_info->bssid[0], HEX )+":"+
  85. String( stat_info->bssid[1], HEX )+":"+
  86. String( stat_info->bssid[2], HEX )+":"+
  87. String( stat_info->bssid[3], HEX )+":"+
  88. String( stat_info->bssid[4], HEX )+":"+
  89. String( stat_info->bssid[5], HEX );
  90. }
  91.  
  92. stat_info = STAILQ_NEXT(stat_info, next);
  93. }
  94. }
  95. }
  96.  
  97. return "";
  98. }
Add Comment
Please, Sign In to add comment