Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
add support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Dec 20, 2021
1 parent a2027e8 commit 99df9b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
17 changes: 2 additions & 15 deletions host/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (m *manager) ApplyGroup(group string, simulate bool) {
return
}
hosts = append(hosts, m.baseHost)
combinedHostContent := m.combineHosts(hosts, "# Auto generated from group "+group)
combinedHostContent := m.combineHosts(hosts, "# Auto generated from "+group)

// just print
if simulate {
Expand Down Expand Up @@ -389,19 +389,6 @@ func (m *manager) printHosts() {
}
}

func (m *manager) printGroups() {
if len(m._groups) != len(m.groups) {
panic("the size of _groups and groups is not equal")
}
fmt.Printf("All Groups\n")
for _, group := range m._groups {
fmt.Println("\t[group]", group)
for _, host := range m.groups[group] {
fmt.Printf("\t\t[host] %+v\n", host)
}
}
}

func (m *manager) combineHosts(hosts []*Host, head string) []byte {
var b bytes.Buffer
b.WriteString(head)
Expand All @@ -412,7 +399,7 @@ func (m *manager) combineHosts(hosts []*Host, head string) []byte {
display.Panic("can not combine host", err)
}
scanner := bufio.NewScanner(file)
b.WriteString("# Host section from " + host.Name + NewLine)
b.WriteString("# " + host.Name + NewLine)
for scanner.Scan() {
b.Write(scanner.Bytes())
b.WriteString(NewLine)
Expand Down
22 changes: 20 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
![test](https://github.com/ingbyr/gohost/actions/workflows/test.yml/badge.svg)
![release](https://github.com/ingbyr/gohost/actions/workflows/release.yml/badge.svg)

Gohost is a simple host switcher tool supporting Linux and macOS.
Gohost is a simple host switcher tool supporting Windows, Linux and macOS.

**To modify the system host file gohost need running in root mode**

- For Windows user: open console in admin mode.
- For Linux and macOS user: use `sudo gohost` or login as root


## For Windows User

If new hosts not working, you probably need disable `DNS Client Service` by excuting below command in powershell (admin mode) and reboot your compouter.
```powershell
REG add "HKLM\SYSTEM\CurrentControlSet\services\dnscache" /v Start /t REG_DWORD /d 4 /f
```

Also you can enbale `DNS Client Service` again by excuting in powershell (admin mode).

```powershell
REG add "HKLM\SYSTEM\CurrentControlSet\services\dnscache" /v Start /t REG_DWORD /d 2 /f
```

**To modify the system host file gohost need running in root mode, such as `sudo gohost`.**

## Usage

Expand Down

0 comments on commit 99df9b0

Please sign in to comment.