I just want to get the same info I can retrieve from the Bitcoin network by typing the command within the Bitcoin Core CLI without using it.
It is actually quite easy to do so. The difficulty and the target are both stored within the block headers, it will be sufficient to just call the block headers at each difficulty epoch to get the difficulty for that period. It is pointless to get the hashrate, because any estimation based on timestamps within a short period of time is often quite inaccurate. You can determine it based on the block intervals or use the difficulty as a metric.