A spate of hacking attacks has put U.S. states on edge, with election officials rushing to plug cybersecurity gaps with help from the federal government.

Nine states have asked for "cyberhygiene" scans in which the Department of Homeland Security looks for vulnerabilities in election authorities' networks that are connected to the internet, according to a DHS official. With the election coming up soon, DHS wants more states to sign up.

The threat — primarily from foreign hackers or intelligence agencies — affects states that are reliably Democratic or Republican as well as key battleground states, including Pennsylvania and Ohio, officials and cybersecurity experts said.