Sign in to follow this  
Followers 0
John117

Help converting code.

7 posts in this topic

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



Wtf is a long and short IP?

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Hatcheda

Share this post


Link to post
Share on other sites

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)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0