Jump to content

Recommended Posts

Posted (edited)

I couldnt find this func in a search, but I dont have smashing search skills

so apologies if its already knocking about.

Converts an IP Address to and Integer and visaversa.

Solution calculations from: http://www.aboutmyip.com/

EDIT: 15th Jan 2013

Google changed IP, updated to keep example working.

; Example 1. use google IP
$_Ipv4ToInt = _Ipv4ToInt("173.194.66.94")
MsgBox(0,"_Ipv4ToInt",$_Ipv4ToInt)
ShellExecute("http://" & $_Ipv4ToInt)

; Example 2. Use int generated from _Ipv4ToInt
$_IntToIpv4 = _IntToIpv4($_Ipv4ToInt)
MsgBox(0,"_IntToIpv4",$_IntToIpv4)
ShellExecute("http://" & $_IntToIpv4)
;=============================================================================
;                        Converts an Int into an IP
;=============================================================================
Func _IntToIpv4($_Int)
    $oct1 = $_Int / 16777216
    $_Int = Mod($_Int, 16777216)
    $oct2 = Int($_Int) / 65536
    $_Int = Mod($_Int, 65536)
    $oct3 = $_Int / 256
    $_Int = Mod($_Int, 256)
    $oct4 = $_Int
    $sIP = Int($oct1) & "." & Int($oct2) & "." & Int($oct3) & "." & Int($oct4)
    Return String($sIP)
EndFunc   ;==>_IntToIpv4


;=============================================================================
;                         Converts an IP into an int
;=============================================================================
Func _Ipv4ToInt($_IP)
    $aIP = StringSplit($_IP, ".", 3)
    $oct1 = Int($aIP[0]) * (256 ^ 3)
    $oct2 = Int($aIP[1]) * (256 ^ 2)
    $oct3 = Int($aIP[2]) * (256)
    $oct4 = Int($aIP[3])
    $iInt = $oct1 + $oct2 + $oct3 + $oct4
    Return $iInt
EndFunc   ;==>_Ipv4ToInt
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

Nice, didn't know you could access Google using an integer! :x

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

It might be a stupid question, but I like to think we're on the same page :x I thought I would just create a quick Function for _IPv4ToBinary() but I couldn't think of a way to convert an Integer to Binary (e.g. 0001010)? Obviously Binary() isn't the answer!!?

Edit: Searched _DecToBinary() [sOLVED]

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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