;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfIPToHexV1 (strIP) strHex = "" intCount = ItemCount (strIP, ".") For intI = 1 To intCount intByte = 0 + ItemExtract (intI, strIP, ".") strHex = strHex : Num2Char ((intByte >> 4) + 48 + 7 * ((intByte >> 4) > 9)) : Num2Char ((intByte & 15) + 48 + 7 * ((intByte & 15) > 9)) ; Uppercase. Next Return strHex ;.......................................................................................................................................... ; strHex = StrCat(strHex,Num2Char((intByte>>4)+48+39*((intByte>>4)>9)),Num2Char((intByte&15)+48+39*((intByte&15)>9))) ; Lowercase. ;.......................................................................................................................................... ; This UDF "udfIPToHex" returns a string, that contains the uppercase hexadecimal representation of an ip number string. ; ; Example: ; strIP = "192.168.15.31" ; Must be a valid IP number string. ; Result: ; strHex = "C0A80F1F" ;.......................................................................................................................................... ; Detlev Dalitz.20030630.20100207. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfHexToIPV1 (strHex) strIP = "" strHex = StrUpper (StrTrim (strHex)) intLen = StrLen (strHex) For intI = 1 To intLen By 2 intN1 = Char2Num (StrSub (strHex, intI, 1)) - 48 intN2 = Char2Num (StrSub (strHex, intI + 1, 1)) - 48 intByte = ((intN1 - 7 * (intN1 > 9)) << 4) + (intN2 - 7 * (intN2 > 9)) strIP = ItemInsert (intByte, -1, strIP, ".") Next Return strIP ;.......................................................................................................................................... ; This UDF "udfHexToIP" returns a string, that contains the IP number representation of a hexadecimal string. ; ; Example: ; strHex = "c0a80f1f" ; Must be a valid hexstring that can be translated into ip numberstring. ; Result: ; strIP = "192.168.15.31" ;.......................................................................................................................................... ; Detlev Dalitz.20030630.20100207. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfIPToHexV2 (strIP) intHigh = ItemCount (strIP, ".") hdlBB = BinaryAlloc (intHigh) intHigh = intHigh - 1 For intI = 0 To intHigh BinaryPoke (hdlBB, intI, ItemExtract (intI + 1, strIP, ".")) Next strHex = BinaryPeekHex (hdlBB, 0, 4) hdlBB = BinaryFree (hdlBB) Return strHex ;.......................................................................................................................................... ; This UDF "udfIPToHex" returns a string, that contains the uppercase hexadecimal representation of an ip number string. ; ; Example: ; strIP = "192.168.15.31" ; Must be a valid IP number string. ; Result: ; strHex = "C0A80F1F" ;.......................................................................................................................................... ; Detlev Dalitz.20030630.20100207. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfHexToIPV2 (strHex) strIP = "" intHigh = (1 + StrLen (strHex)) / 2 hdlBB = BinaryAlloc (intHigh) BinaryPokeHex (hdlBB, 0, strHex) intHigh = intHigh - 1 For intI = 0 To intHigh strIP = ItemInsert (BinaryPeek (hdlBB, intI), -1, strIP, ".") Next hdlBB = BinaryFree (hdlBB) Return strIP ;.......................................................................................................................................... ; This UDF "udfHexToIP" returns a string, that contains the IP number representation of a hexadecimal string. ; ; Example: ; strHex = "c0a80f1f" ; Must be a valid hexstring that can be translated into ip numberstring. ; Result: ; strIP = "192.168.15.31" ;.......................................................................................................................................... ; Detlev Dalitz.20030630.20100207. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strIP = "192.168.15.31" strHex1 = udfIPToHexV1 (strIP) ; "C0A80F1F". strHex2 = udfIPToHexV2 (strIP) ; "C0A80F1F". strIP1 = udfHexToIPV1 (strHex1) ; "192.168.15.31". strIP2 = udfHexToIPV2 (strHex2) ; "192.168.15.31". Exit