John117 1 Posted August 31, 2007 I am converting a Short IP to long IP / Long Ip to Short IP section and am stuck on the "%" character. I can't figure out what it is doing. -A logic question really. everything works until there. The return of Section 1 should be 64 which is the first part of the IP Section 2 should be 4 but I dont understand what the % is doing. I have tried reversing and dividing 256,3 by LIP to get the percentile but that doesn't seem to be it. Can anyone suggest idea's? CODE; Convert Short IP to long IP Global $avSampleData[1] = ["64.4.32.7"] For $n = 0 To UBound($avSampleData) - 1 $avSplit = StringSplit($avSampleData[$n], ".") Next $LongIP = ($avSplit[1]*("256" * "256" * "256"))+($avSplit[2]*("256" * "256"))+($avSplit[3] * "256") + ($avSplit[4]) MsgBox(0, "LongIP", $LongIP) ; Covert Long IP to Short IP ; Section 1 ;var SIP1=floor(LIP/pow(256,3)); $SIP1 = ($LongIP/("256" * "256" * "256")) MsgBox(0, "SIP", $SIP1) ;Has to be trimed down MsgBox(0, "SIP", "" & StringReplace(StringMid(($LongIP/("256" * "256" * "256")), 1, 3), ".", "")) ; Section 2 ;var SIP2=floor((LIP%pow(256,3))/pow(256,2)); $SIP2 =(($LongIP/("256" * "256" * "256"))/(256*256)) ;Not working $SIP2 =((("256" * "256" * "256")/$LongIP)/(256*256)) ;Not working either MsgBox(0, "SIP", $SIP2) ; Section 3 ;var SIP3=floor(((LIP%pow(256,3))%pow(256,2))/pow(256,1)); ;$SIP3 ; Section 4 ;var SIP4=floor((((LIP%pow(256,3))%pow(256,2))%pow(256,1))/pow(256,0)); ;$SIP4 Share this post Link to post Share on other sites
weaponx 16 Posted August 31, 2007 Wtf is a long and short IP? Share this post Link to post Share on other sites
John117 1 Posted August 31, 2007 (edited) A short ip is 64.233.167.104 "Google.com" A long IP is 1089054568 Also "Google" -but not always blocked by web filters. edit: forgot I had replaced it with hotmail and your language is really uncalled for! Edited August 31, 2007 by Hatcheda Share this post Link to post Share on other sites
Jos 2,281 Posted August 31, 2007 how about? ; Convert Short IP to long IP Global $avSampleData[1] = ["64.4.32.7"] For $n = 0 To UBound($avSampleData) - 1 $avSplit = StringSplit($avSampleData[$n], ".") Next $LongIP = $avSplit[1] * 256 ^ 3 + $avSplit[2] * 256 ^ 2 + $avSplit[3] * 256 + $avSplit[4] MsgBox(0, "LongIP", $LongIP) ; Covert Long IP to Short IP ; Section 1 $SIP1 = Int($LongIP / (256 * 256 * 256)) MsgBox(0, "SIP", $SIP1) ; Section 2 $LongIP = $LongIP - $SIP1 * 256 ^ 3 $SIP2 = Int($LongIP / 256 ^ 2) MsgBox(0, "SIP2", $SIP2) ; sect 3 $LongIP = $LongIP - $SIP2 * 256 ^ 2 $SIP3 = Int($LongIP / 256) MsgBox(0, "SIP3", $SIP3) ; sect 3 $LongIP = $LongIP - $SIP3 * 256 $SIP4 = Int($LongIP) MsgBox(0, "SIP4", $SIP4) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
SkinnyWhiteGuy 2 Posted August 31, 2007 In most programming languages I've seen, the "%" operator, as used above, is the Modulus function. In AutoIt, that would be the Mod() function. Share this post Link to post Share on other sites
John117 1 Posted August 31, 2007 how about?That's a very good rewrite. -learning a lot of options I have yet to to see! Thanks (works btw) Share this post Link to post Share on other sites
John117 1 Posted August 31, 2007 In most programming languages I've seen, the "%" operator, as used above, is the Modulus function. In AutoIt, that would be the Mod() function.-Thanks! Share this post Link to post Share on other sites