Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isIP('1.1.1.01') = true? #534

Closed
mentalmap opened this issue May 31, 2016 · 11 comments
Closed

isIP('1.1.1.01') = true? #534

mentalmap opened this issue May 31, 2016 · 11 comments

Comments

@mentalmap
Copy link

"1.1.1.01" is an invalid ip address.

@mentalmap mentalmap changed the title isIP(1.1.1.01) = true? isIP('1.1.1.01') = true? May 31, 2016
@chriso
Copy link
Collaborator

chriso commented May 31, 2016

Is it invalid? There was some discussion in #490.

@mentalmap
Copy link
Author

mentalmap commented Jun 1, 2016

For obvious reasons, it's invalid.

Just a Javascript sample:

var net = require('net');
var client = new net.Socket();

// 54.235.131.019 is ip address of api.ipify.org
client.connect(80, '54.235.131.019', function() {
    client.write('GET / HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n');
});

client.on('data', function(data) {
    console.log('Received: ' + data);
    client.destroy();
});

client.on('close', function() {
    console.log('Connection closed');
});

If "54.235.131.019" is valid, then the program would get result. but not!

BTW, The program get success result in Mac, but not in Linux(eg: Centos 7).

@chriso
Copy link
Collaborator

chriso commented Jun 1, 2016

Not saying that I disagree with you, but whether or not the node.js net module accepts leading zeroes says nothing about whether they're valid everywhere. I'll need a RFC reference before making any changes.

@chriso
Copy link
Collaborator

chriso commented Jun 1, 2016

BTW, The program get success result in Mac, but not in Linux(eg: Centos 7).

So on Mac OS X you get the same result with leading zeroes?

@mentalmap
Copy link
Author

On Mac OS X, IP with leading zeroes is ok.

@chriso
Copy link
Collaborator

chriso commented Jun 1, 2016

@chriso
Copy link
Collaborator

chriso commented Jun 1, 2016

ping on OS X interprets octets with leading zeroes as octal notation:

$ ping 8.8.8.010
PING 8.8.8.010 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=47 time=53.670 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=47 time=60.050 ms

@mentalmap
Copy link
Author

PING is OK(Mac and Linux), but not in node client.

@mentalmap
Copy link
Author

In WIKI:

But this also means addresses where an IP address component is written with a leading zero digit may be interpreted differently by different programs: some will ignore the leading zero, some will interpret the number as octal.

That results in inconsistent result.

@chriso
Copy link
Collaborator

chriso commented Jun 1, 2016

Right, but leading zeroes are still technically valid in some cases. Whether or not <insert_tool_or_lib_here> supports them are outside the scope of this library.

@chriso chriso closed this as completed Jul 15, 2016
@orekav
Copy link

orekav commented Oct 16, 2019

Maybe it could be replaced by:
/(^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants