Jump to content


Photo

Ip Scripts


  • Please log in to reply
6 replies to this topic

#1 smart_monkey

smart_monkey

    GMC Member

  • GMC Member
  • 91 posts

Posted 30 June 2009 - 04:57 AM

IP Scripts

I created a series of scripts which do a variety of different things with IP addresses and subnet masks. I have error checked the scripts and they do work but if anyone finds any errors, please leave a post and I may correct it.

If you use the scripts, please give credit. The Network ID script took several hours to make and fix bugs.

Also, not all scripts have full error checking, like if you format an IP address with commas then it wont work etc.

Download Link

Scripts include:
IP_Get_Class(IP);
Returns the Class that the IP Address is in. (A, B, C, D or E)

IP_Is_Real(IP);
Returns true or false depending if it is a valid IP Address.

IP_Default_Subnet(IP);
Returns the default subnet based on the class that the IP Address is in.

IP_Get_Network_ID(IP, Subnet Mask);
Returns the Network ID from the subnet mask and IP address.
(Note: This script took me hours to get fully working. If you find any problems with it tell me.)

IP_Subnet_Is_Real(Subnet Mask);
Returns true or false depending if it is a valid Subnet Mask.

IP_Convert_To_Binary(8-bit Decimal Number);
Converts an 8-bit Number to Binary. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

IP_Convert_To_Decimal(8-bit Binary Number);
Converts an 8-bit Binary Number to Decimal. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

IP_Useable_Subnets(Bits Borrowed "CIDR");
Using the method of (2^n-2) returns the amount of subnets avaliable.

IP_Recommend_Bits(# Of Hardware);
Enter the amount of hardware you would want on a single network and returns the Bits Borrowed (CIDR).

IP_Check_Reserved(IP);
Checks to see if an IP Address range is reserved.
(Note: I didnt finish this script yet so it does not contain all the Reserved Ranges and it is the reason why you cant try the script in the demo but it is in the GM6 file. The list of ranges is from Wikipedia.)

IP_Subnet_To_Bits(Subnet Mask);
Converts a Subnet Mask to a CIDR value and returns that value.
  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9603 posts
  • Version:GM:Studio

Posted 30 June 2009 - 07:18 AM

IP_Convert_To_Binary(8-bit Decimal Number);
Converts an 8-bit Number to Binary. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

IP_Convert_To_Decimal(8-bit Binary Number);
Converts an 8-bit Binary Number to Decimal. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

I didn't try the scripts, but I'm curious about these two. Was there any reason you didn't just use a bitwise AND operator ("&")?

-IMP :P :P
  • 0

:GM123: Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea :)

:bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny:


#3 smart_monkey

smart_monkey

    GMC Member

  • GMC Member
  • 91 posts

Posted 30 June 2009 - 07:24 AM

IP_Convert_To_Binary(8-bit Decimal Number);
Converts an 8-bit Number to Binary. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

IP_Convert_To_Decimal(8-bit Binary Number);
Converts an 8-bit Binary Number to Decimal. I only created this to convert each octet so I was able to "AND" them together in the IP_Get_Network_ID script.

I didn't try the scripts, but I'm curious about these two. Was there any reason you didn't just use a bitwise AND operator ("&")?

-IMP :P :P


I didnt know game maker already had such a thing unless I don't fully understand what you mean.. Those two scripts aren't necessarily for the game maker user to use but for my Network ID script.

Those scripts themselves only convert the numbers (binary to decimal and decimal to binary). The IP_Get_Network_ID script is the one that does the ANDing operation. Look in that script to see how I did it.
  • 0

#4 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9603 posts
  • Version:GM:Studio

Posted 30 June 2009 - 10:43 PM

I'm saying there's no need to convert to binary to AND two numbers.

For example, you can do this:

num1=128;

Then to set the third bit from the right to 1, you can do:

num1&=4;

You could also, in that case, add 4 (which is 2^2), but in cases where your numbers are not powers of 2 it's better to use bitwise & than just adding numbers. Plus, from what I've heard (but never really tested), bitwise operators are faster than arithmetic operators anyway.

A nice reference:

&& = Logical AND
& = Bitwise AND
|| = Logical OR
| = Bitwise OR
^^ = Logical XOR
^ = Bitwise XOR
<< = Bitwise SHIFT LEFT
>> = Bitwise SHIFT RIGHT


-IMP :D :)
  • 0

:GM123: Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea :)

:bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny:


#5 smart_monkey

smart_monkey

    GMC Member

  • GMC Member
  • 91 posts

Posted 01 July 2009 - 08:59 AM

Ok, I will have a look into it. It seems funny that what I thought was so complicated to do is something that simple.
  • 0

#6 slayer 64

slayer 64

    Slayer of gingers

  • GMC Member
  • 4301 posts
  • Version:GM:Studio

Posted 05 July 2009 - 01:07 AM

nice scripts. i don't know what they're for, but they look useful.
i pushed Q, entered 123, and got an error.
___________________________________________
ERROR in
action number 1
of Key Release Event for Q-key Key
for object obj_control:

In script IP_Subnet_To_Bits:
Error in code at line 15:
	   while (Octect<5)

at position 13: Unknown variable Octect

  • 0

5y5rs3d.pngfg0UQNL.png


#7 smart_monkey

smart_monkey

    GMC Member

  • GMC Member
  • 91 posts

Posted 05 July 2009 - 07:20 AM

I fixed up that error and I made the IP_Subnet_Is_Real better by making it work out more errors in the subnet mask.

Also, technically, the number 123 should have come up false as the subnet mask is not real. A valid subnet mask is 4 octects each being in between 0 and 255.

eg. 255.255.0.0 or 255.255.248.0 or 255.0.0.0 or any variation that is valid.

If anyone has found any other errors, tell me.
  • 0