Difference between revisions of "$iptype"

From Scriptwiki
Jump to: navigation, search
m (Added category)
m (Added examples)
 
Line 15: Line 15:
 
== Examples ==
 
== Examples ==
  
  [[If-Then-Else|if]] (!$iptype(%ip)) {
+
$iptype(255.255.255.255)
   [[echo]] -ag Invalid IP Address!
+
Returns ''ipv4''.
 +
 
 +
$iptype(FF::FF)
 +
Returns ''ipv6''.
 +
 
 +
$iptype(FF::FF).expand
 +
Returns ''FF:0:0:0:0:0:0:FF''.
 +
 
 +
  [[If-Then-Else|if]] (!$iptype([[$ip]])) {
 +
   [[echo]] -ag $ip is an invalid IP Address!
 
  }
 
  }
  [[If-Then-Else|elseif]] ($iptype(%ip) == ipv4) {
+
  [[If-Then-Else|elseif]] ($iptype([[$ip]]) == ipv4) {
   [[echo]] -ag %ip is an IPv4 address
+
   [[echo]] -ag $ip is an IPv4 address
 
  }
 
  }
  [[If-Then-Else|elseif]] ($iptype(%ip) == ipv6) {
+
  [[If-Then-Else|elseif]] ($iptype([[$ip]]) == ipv6) {
   [[echo]] -ag %ip is an IPv6 address, compressed: $iptype(%ip).compress ; expanded: $iptype(%ip).expand
+
   [[echo]] -ag $ip is an IPv6 address, compressed: $iptype($ip).compress ; expanded: $iptype($ip).expand
 
  }
 
  }
This [[echo]]s the IP type if valid.
+
This [[echo]]s the IP type if valid of the local ip address.
  
 
[[Category:Identifiers]]
 
[[Category:Identifiers]]

Latest revision as of 13:16, 5 March 2011

Returns "ipv4" or "ipv6" if text is is a valid IP address format.

$iptype(text)

Where text is the address to check its type.

The following properties are available for $iptype:

Property Description
compress compresses the address (IPv6)
expand expands the address (IPv6)

Examples

$iptype(255.255.255.255)

Returns ipv4.

$iptype(FF::FF)

Returns ipv6.

$iptype(FF::FF).expand

Returns FF:0:0:0:0:0:0:FF.

if (!$iptype($ip)) {
  echo -ag $ip is an invalid IP Address!
}
elseif ($iptype($ip) == ipv4) {
  echo -ag $ip is an IPv4 address
}
elseif ($iptype($ip) == ipv6) {
  echo -ag $ip is an IPv6 address, compressed: $iptype($ip).compress ; expanded: $iptype($ip).expand
}

This echos the IP type if valid of the local ip address.