There's no 100% way to actually know. Its more like a guesstamation.
Take into account what kind of Villian it is.
Loose or tight.
The type of villain will tell you most about his range. Tight players play good cards, and loose players play all kinds of different kinds of cards.
Then consider what position villian is limping/raising in.
The earlier position the stronger the hand and vice-a-versa, usually, but you can get a monster in late position also. Position helps me narrow it down a bit.
The texture of the board matters like is there a flush draw or straight draw.
Another way to get a better read is instead of calling start raising it will define the hand more. Dont call with second pair raise with it, someone can only call you if they have you beat or on a draw.
(Theres alot of donks out there that will call with bottom pair but lets assume were dealing with someone who knows what there doing, calling with bottom pair just isnt profitable IMO. In most cases.)
It really depends on the texture of the board.
Villain type and the board texture combined with bets/raises postflop should considerably narrow down the possible RANGE of cards villain can hold.
Hope this helps.