zdns icon indicating copy to clipboard operation
zdns copied to clipboard

Windows not supported

Open AdhirRamjiawan opened this issue 8 years ago • 10 comments

The config line in main.go doesn't support the Windows operating system. I had to change the line to the following with a custom text file to register nameservers:

config_file := flags.String("conf-file", "c:\\Users\\Adhir\\Documents\\resolv.conf", "config file for DNS servers")

Ideally it should determine what OS you're on then select the file accordingly if possible

AdhirRamjiawan avatar Sep 06 '17 22:09 AdhirRamjiawan

Perhaps it is convenient to incorporate a .conf file with default values ​​inside the repository, and load it when the platform is Windows instead of "/etc/hosts" :thinking:

What do you think?

matricali avatar Feb 03 '20 16:02 matricali

I think that's fine, though if there's a conf file, we'd want it to be able to handle all the options passed in on the command line. I don't think it makes sense to have a conf that only specifies the equivalent of /etc/hosts. None of the core maintainers of ZDNS use Windows, so this is something that would need an external contribution.

zakird avatar Feb 03 '20 17:02 zakird

I do not use Windows as my main platform, but I can help by sending a pull request I think.

I'm thinking something like this:

config_file_path = "/etc/resolv.conf"

IF PLATFORM == Windows THEN
    config_file_path = HOME_DIR + "\\resolv.conf.zmap"
    IF path NOT EXISTS THEN
        WRITE DEFAULT VALUES to HOME_DIR + "\\resolv.conf.zmap"
    ENDIF
ENDIF

The default content for resolv.conf.zmap would be something like this:

nameserver 8.8.8.8
nameserver 8.8.4.4

Perhaps it would be appropriate to print a warning that the file was created with its default values.

matricali avatar Feb 03 '20 17:02 matricali

I'm not sure if this really needs an extra conf file. We could just default to set a set of resolvers if nothing is passed in on the command line and we can't find an equivalent to /etc/resolv.conf.

There's also probably a way to just ask Windows what its resolvers are, similar to reading /etc/resolv.conf.

zakird avatar Feb 03 '20 17:02 zakird

I do not use Windows as my main platform, but I can help by sending a pull request I think.

I'm thinking something like this:

config_file_path = "/etc/resolv.conf"

IF PLATFORM == Windows THEN
    config_file_path = HOME_DIR + "\\resolv.conf.zmap"
    IF path NOT EXISTS THEN
        WRITE DEFAULT VALUES to HOME_DIR + "\\resolv.conf.zmap"
    ENDIF
ENDIF

The default content for resolv.conf.zmap would be something like this:

nameserver 8.8.8.8
nameserver 8.8.4.4

Perhaps it would be appropriate to print a warning that the file was created with its default values.

	var config_file_path = "/etc/resolv.conf"

	if runtime.GOOS == "windows" {
		// We don't have any resolv.conf in Windows
		usr, err := user.Current()
	    if err != nil {
	        log.Fatal(err)
	    }
		config_file_path = usr.HomeDir + "\\.resolv.conf.zmap"

		if _, err := os.Stat(config_file_path);
		os.IsNotExist(err) {
			log.Warningf("Creating default configuration file for DNS servers in %s", config_file_path)
			config_file_defaults := []byte("nameserver 8.8.8.8\nnameserver 8.8.4.4\n")
			err := ioutil.WriteFile(config_file_path, config_file_defaults, 0644)
			if err != nil {
				log.Fatalf("Unable to write file (%s): %s", config_file_path, err.Error())
			}
		}
	}

matricali avatar Feb 03 '20 17:02 matricali

I'm not sure if this really needs an extra conf file. We could just default to set a set of resolvers if nothing is passed in on the command line and we can't find an equivalent to /etc/resolv.conf.

There's also probably a way to just ask Windows what its resolvers are, similar to reading /etc/resolv.conf.

Good point, I will investigate a little

matricali avatar Feb 03 '20 17:02 matricali

This would be great!

But please use the canonical Windows configuration directory NOT the user's home or documents directories - applications that cram these full of config files are super annoying as they are for documents and personal files, not configuration..

https://github.com/shibukawa/configdir is a good library for doing this cross-platform!

Southclaws avatar Feb 29 '20 13:02 Southclaws

I believe this should be fixed in #257. Can you test and see if the problem is resolved in master?

zakird avatar Jan 23 '22 19:01 zakird

This error has been fixed, it works on Windows

ksv87 avatar Feb 10 '22 11:02 ksv87

image

ksv87 avatar Feb 10 '22 11:02 ksv87