//参数ip
void configservice::save_ip_domain_host(std::string ip)
{
std::stringstream ss;
std::string domain = "glscsmp.com";
std::string ipdomain = ip + " " + domain + "\n";
std::string hostfile = "C:\\Windows\\System32\\drivers\\etc\\hosts";
std::ifstream inf(hostfile, ios_base::in);
bool find = false;
if (inf.is_open())
{
std::string line;
while (std::getline(inf, line))
{
if (line.find(domain) != std::string::npos)
{
find = true;
ss << ipdomain;
}
else
{
ss << line << "\n";
}
}
inf.close();
if (!find)
{
ss << ipdomain;
}
std::string outstr = ss.str();
std::ofstream ofs(hostfile, ios_base::out);
if (ofs.is_open())
{
ofs << outstr;
ofs.close();
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39