I was googling for a list of non-real or private or localhost other than 127.0.0.x but no success. Can someone give a list or a link to a list?
The following three ranges are private
10.0.0.0 – 10.255.255.255
172.16.0.0 – 172.31.255.255
192.168.0.0 – 192.168.255.255
Thanks and what are local other than 127.0.0.* ?
private networks are usually local
For first I can use 10/24 for the last I can use 192.168/16 to wildcard them. How to wildcard the second one?
like the third one.
Are you sure? But the second part of second one us from 16 to 32 not to 255. It seems you are wrong?
A quick search for “172.16 net mask” gives this: https://en.wikipedia.org/wiki/Private_network which suggests you would use
The first one does not mean from 10.0.0.0 until 10.0.0.255? Shouldn’t I block until 10.255.255.255 instead?
No, I’ve always thought of it as the number of unchanging bits in the binary version of the address, so /8 means that the first eight don’t change and the remaining 24 can, giving a range from 10.0.0.0 to 10.255.255.255 (or probably .254).
Using the older-style subnet notation (which I sometimes find easier to understand) that would be 10.0.0.0 with subnet 255.0.0.0.
And how is possible to define a fake domain name e.g. example.com on a localhost? And does gethostbyaddr() returns the private ip associated with that domain on local host?
Depends on your system. On a Windows 7 PC, edit
\windows\system32\drivers\etc\hosts. and add a line like this:
Note that filename is
hosts., i.e. it has no extension on it. You can then open
http://example.dev in your browser. I use
.dev for local versions of sites so I can be sure I am working locally, if you use the actual name it will give you a problem when you want to access the “live” site because, if I remember correctly, hosts entries overrule dns entries.
I would doubt that
gethostbyaddr() would work if there is more than one host name defined for the same localhost address - how would it know which one to return? But your question is strange - you ask about using
gethostbyaddr() to “return the private ip associated with that domain” - but surely that function returns the name associated with the ip, rather than the ip associated with the name?
So how can I be sure if my script is not used on a localhost but on a real site? is there a way to check it?
Wouldn’t calling the domain ‘.dev’ or something else other than your proper domain do it? If you’re running the test version on your localhost then the address bar would show .dev, if it’s on the live server it would show .com. I might not understand what you’re asking, though.
I meant verifying it with a php code since we don’t know this is .dev or something else. Possible?
I usually use .local for local copies of sites.
Apparently if you were to apply domain names that don’t contain any dots at all then they are assumed to be on the local machine eg localhost
For localhost is possible to set any ip? Or only private ip or 127.* is possible to define for localhost?
The point of
localhost and the
127.0.0.1 address (and
::1 on IPv6) is that it’s a fixed, reserved way of knowing that you’re referring to “this machine”. It wouldn’t really work if it could be altered, then it would just be any old address and you’ve have to have certain bits of information to be able to figure it out.