Pakistan has ordered 1.7 million Afghans who it said were living undocumented in the country to leave by November 1 or face deportation, in an unprecedented crackdown.