No, it's not quite illegal; I have in front of me a little (A5 size) book published by BT in 1996 called The Phone Book Companion, which lists all the landline codes in order then gives the town that number is from. For example:
01750 is the Selkirk area of southern Scotland
01751 covers part of the Yorkshire wolds
01752 is Plymouth
01753 is Slough*
01754 is Skegness, etc. etc.
*but 01753 65xxxx is Iver (Bucks)
01753 83xxxx is Windsor (Berks)
01753 88xxxx is Gerrards Cross
That should narrow it down to a town (or sometimes even village); then it's down to more local knowedge.