Surely there must be some database somewhere, like maxmind?
There's a few ways to guess the carrier by the phone number, but there's number portability all over the place, so if you want reliable data, you really need to do a lookup (or dip as they're sometimes called) into the relevant national portability database, and that costs money, sometimes about the same as just paying for an SMS.
If you want to do it in the US based on original assignments, you can download the original assignments from NANPA's web-o-site, but you're going to need to spend some serious time on data cleanup, FWIW.
For other countries, Google's libphonenumber has some info on range -> operator, but portability is still the elephant in the room.