There's no accurate way of doing so as all the information you get from user request's headers which can easily be changed by user and can contain just anything.
If you're OK with reading probably inaccurate information then you may want to check this SO answer to similar question