Islamic State fighters have seized dozens of villages close to the border, prompting the flight of thousands.