-1

Why pure javascript running as client side code on browser cannot get the public IP of a client?

I know that public IP address can retrieved by making a call to a server. But I am more interested in the reason as to why pure js can do the job.

I reviewed this question: How to get client's IP address using JavaScript?. The answers rather provides solution but doesn't gives information on whey it is not possible.

Maninder Singh
  • 177
  • 1
  • 9
  • 1
    "Pure javascript" can't do anything, it doesn't have any IO. I suppose you refer to the various APIs that are exposed to JS running in a browser? – Bergi Aug 09 '22 at 01:13
  • @Bergi That is what I meant, I have updated my question better reflect that. Sorry for the confusion earlier. – Maninder Singh Aug 09 '22 at 04:20

1 Answers1

2
  1. Privacy. Direct access to the host machine's resources is only accessible with user permission, but this isn't the only reason.

  2. Routing with NAT: the public address is often set on the outside interface of a router. Mostly there's no way to get that information without logging in to the router (but see 1. above), or asking some other external machine to tell you.