IP-addresses stored as int results in overflow?

后端 未结 11 482
無奈伤痛
無奈伤痛 2021-02-02 12:27

I\'m writing a chat-server in node.js, and I want to store connected users IP-addresses in a mysql database as (unsigned) integers. I have written a javascript method to convert

11条回答
  •  情话喂你
    2021-02-02 13:16

    var aaa = Number("0b"+ "192.168.2.44".split(".").map(
      function(dec){
        return ("00000000" + Number(dec).toString(2)).slice(-8); 
      }).join(""));
    
    aaa.toString(2).match(/.{1,8}/g).map(
      function(bin){
        return Number("0b"+bin); 
      }).join(".");
    

提交回复
热议问题