I'm writing a website where the server is on a pi running a C program using libwebsockets. I'm wondering if it's possible to determine if the host is local (connected from LAN) or remote (from WAN). I'd like to limit what the web page can do if it's from a remote source.
Asked
Active
Viewed 104 times
1 Answers
0
You can use the lws_get_peer_simple function to obtain the IP address:
char name[16];
lws_get_peer_simple(wsi,name,16);
From there, it should be easy to determine if the IP address is in local subnets. One way to do it is by simple string comparisons:
if(strstr(name,"10.")==name)return(LOCAL_NET);
if(strstr(name,"192.168."==name))return(LOCAL_NET);
return(PUBLIC_NET);

programagor
- 288
- 4
- 12