-1

<script type="text/javascript" src="data:application/octet-stream;base64,dXNlcmlwID0gIjcxLjExLjE4OC4xODkiOw=="></script>
<input id=userip type="hidden" >
<script type="text/javascript">
  console.log("Your IP is :", userip);
</script>

I am trying to get ip of my website's visitors so i can know how many non repeating visitors i have. but i havent have any luck achieving the ip there s people saying ip is no longer available due to privacy or so but i found this code that can at least give me the ip but it s a html script code and i have problems transferring that data or var called userip to my back end so i can send it to my email/database (i so called back end) so i am translating a html script code to a back end code or find a back end code that can replace the script code here is the code:

louis
  • 1
  • 6
  • Possible duplicate of [Node.js: Get client's IP](https://stackoverflow.com/questions/19266329/node-js-get-clients-ip) – Nope Jun 07 '18 at 15:42
  • which nodejs framework are you using? – Suresh Prajapati Jun 07 '18 at 15:42
  • express.js i hope this is what you are asking – louis Jun 07 '18 at 15:45
  • Also make sure recording the client's IP address is not against GDPR. According to the GDPR *It's been made clear in the General Data Protection Regulation ("GDPR") that IP addresses should be considered as personal data as the text includes "online identifier", in the definition of "personal data". Recital 30 clarifies that "online identifier" includes IP addresses.* - If users don't agree with you recording their IP address it will impact your visitor stats. That is a huge issue with Google Analytics right now too. – Nope Jun 07 '18 at 15:48
  • Possible duplicate of [How to determine a user's IP address in node](https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node) – FINDarkside Jun 07 '18 at 15:48
  • "Nope" Thank you for your input and I ve checked out that post because I pretty much searched all around the internet but did not find a solution works for me, which i thought this is an easy problem to fix but never thought it would take this long and normally i dont ask much on overstack unless i really need some help because i cant find an answer on the internet. I tried the approaches on that post and the closest i got is something like ::ffff: 0000xxx something which is close to the stuff they had in the post ::ffff:127.0.0.1 i thought i was close so i spent a few days digging in more – louis Jun 07 '18 at 15:50
  • Is your server running on localhost? You'll start getting proper ip addresses when the requests are not coming from localhost. – FINDarkside Jun 07 '18 at 15:53
  • but it seemed like an dead end actually it looks like this the output ::1 instead of ::ffff:127.0.0.1 like it is in the post and i ll post those code below some where since i cant post code in comments – louis Jun 07 '18 at 15:53
  • FINDarkside good point i thought or read about it and i think that is why i tried to post the side on heroku so i can check it but i never got to passing data from front end to my back end (it s normally easy and i ve done it many times but this time is different please see the code/example below for details) let s say even that s the fix i still cant post the correct ip to my back end (by the way my bad i actually found a way to get the ip the code is part of the question i found the way to get an ip but not quite there yet because it still does not work good enough for my application) – louis Jun 07 '18 at 16:02
  • "nope" that s good to know I saw something like that when i was doing some researching on my problem and i thought i m done because they blocked ip or banded it but then i fond the code that at least can get me the ip addresses but just not quite there working perfectly or at least acceptable in my application – louis Jun 07 '18 at 16:05
  • You don't need to post it to the back end, ip is included in every request, otherwise your server couldn't respond at all. I also don't get how sending single string is different from sending other data you might be sending. – FINDarkside Jun 07 '18 at 16:05
  • FINDarkside that s what i thought that i got it but unfortunately that did not help please see the answers i posted below as i have tried it but it did not work – louis Jun 07 '18 at 16:08
  • FINDarkside you just brought up something very interesting that i do not know regarding to "otherwise, server couldn't respond" it seems like server ll check for ip or keep a record of it for book keeping every time when there is a request of communication if that s the case then this should be a easy fix (yea like i always thought but it always turn into a time sink well obviously i am not there yet not that good) please correct me if i am wrong and i hope you dont mind helping me more in that maybe give me a little more details but if my guess is right thats why i tired this in my answers: – louis Jun 07 '18 at 16:14
  • here is the code from the answers. i am just being specific with what i m talking about so i wont confuse everyone at least i m trying. app.use(function(req, res) { var ip = req.clientIp; res.end(ip); }); – louis Jun 07 '18 at 16:18
  • also i thought whenever you talk about server it s considered back end isn't it? I am definitely an entry level so my apology for my inexperience – louis Jun 07 '18 at 16:29
  • You don't need to do manually, it's done automatically (responding). I'm not sure what's the problem anymore, since the problem was that you were testing from localhost. – FINDarkside Jun 07 '18 at 16:31

1 Answers1

0

If you are using nodeJs as backend and ejs for templating you can simply check the request object. With Express: req.ip or trought the HTTP interfaces req.request.connection.remoteAddress

Check this answer for a more extensive explanation

or the documentation for express or http

Emanuele
  • 795
  • 4
  • 13
  • Thank you for the help but i ve tried it as a mentioned in the previous comments but thanks for the remoteAddress part it caught my attention i thought i did not try this but i went back to see the post and my code yea nope it did not work for me it did not do a thing maybe because the stuff "nope" talked about as i ve seen it too that this is the old way which got blocked – louis Jun 07 '18 at 16:25