mysql ip address convert (ip2bigint,bigint2ip)

標簽:mysql ip address convert   瀏覽(735)  日期:2008-03-24
Convert IP address  to bigint

CREATE FUNCTION `F_Ip2Int`(ip varchar(15)) RETURNS bigint(20)
BEGIN
  declare tmp bigint default 0;
  while instr(ip,`.`)>0 do
    set tmp = tmp*256+ left(ip,instr(ip,`.`)-1);
    set ip = right(ip,length(ip)-instr(ip,`.`));
  end while;
  set tmp = tmp*256+ip;
  return tmp;
END

Convert bigint to IP Address

CREATE FUNCTION `F_Int2Ip`(iip bigint) RETURNS varchar(15)
BEGIN

  return concat((iip & 0xFF000000)>>24, `.`,
                (iip & 0x00FF0000)>>16, `.`,
                (iip & 0x0000FF00)>>8, `.`,
                iip & 0x000000FF);

END




-------------------------------------------------
上一篇:用mysqldumpslow分析mysql的slow query log 下一篇:索引有哪些优点?



  
Are you Bot? How you know that?ofcz no.