You have 2 options:
Utilize the API of the carrier, if the carrier offers an API and your carrier module supports it. In that case you need to have an active account with specific permissions to each carrier to use their API. Usually your carrier module asks for API credentials in it's configuration settings.
Use a module which consumes a tracking API, which supports several carriers. For example: ShipTracker