Actually, trying to query the highest supported GL version is quite useless. You should just ask for the lowest GL version (and the most strict profile) your code can work with, and if that is not available, it is not going to work anyway.
If you want to optionally support some features, use of the extension mechanism is the way to go.
If you really want some higher version context on some machines, and a lower one on others, the only reliable way will be to iteratively try to create the context, backwards from the highest version your code can make use of, to the lowest, and just stop when the creation succeeds. You won't get any unknown newer version that way, but since the rest of your code won't make use of any newer features, it is a moot point.
The only reason I can see why you might want some "unknown" newer GL version would be the case of a library, where you create the context and do not know what is to be done with it - like it's the case with GLFW itself. But GLFW has the same issue. There is simply no reliable API to query the highest supported GL version. The recommendation in the GLFW docs, mentioned in @Rabbid76's answer will only provide you the highest available legacy GL version (which limits you to 2.1 on OSX and 3.0 on mesa/linux). It won't work for core profiles, but core profiles are the only reliable way to get modern GL on all platforms.
Having said that all that, I have to admit that I did see code before, which actually iteratively tried the contexts, but started with 5.something, while at the time of writing this answer, the highest existing GL spec was 4.6. Not sure what they were trying to do there, and also no idea which x for 4.x they did start with, after 5.0 failed.