Jump to content

Help converting code.


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...