fix SafeResolv function
This commit is contained in:
		
							parent
							
								
									15120cdd4f
								
							
						
					
					
						commit
						f3bae25ff1
					
				
					 1 changed files with 10 additions and 9 deletions
				
			
		| 
						 | 
					@ -14,24 +14,25 @@
 | 
				
			||||||
:global GlobalFunctionsCustomPhgReady false;
 | 
					:global GlobalFunctionsCustomPhgReady false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# global functions
 | 
					# global functions
 | 
				
			||||||
:global SafelyResolve
 | 
					:global SafeResolve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Function: safelyResolve
 | 
					# Function: safelyResolve
 | 
				
			||||||
#  - Takes a DNS string (e.g. "example.com")
 | 
					#  - Takes a DNS string (e.g. "example.com")
 | 
				
			||||||
#  - Takes an IP type [ipv4, ipv6]
 | 
					#  - Takes an IP type [ipv4, ipv6]
 | 
				
			||||||
#  - Returns a string of and IP address or false if it can't be resolved
 | 
					#  - Returns a string of and IP address or false if it can't be resolved
 | 
				
			||||||
:set SafelyResolve do={
 | 
					:set SafeResolve do={
 | 
				
			||||||
  :do {
 | 
					  :do {
 | 
				
			||||||
    :local DomainName [ :tostr $1 ];
 | 
					    :local DomainName [ :tostr $1 ];
 | 
				
			||||||
    :if ( [ :tostr $2 ] = "ipv4" or [ :tostr $2 ] = "ipv6" ) do={
 | 
					    :local IPType;
 | 
				
			||||||
      :local IPType [ :tostr $2 ];
 | 
					    :if ( ([ :tostr $2 ] = "ipv4") or ([ :tostr $2 ] = "ipv6") ) do={
 | 
				
			||||||
 | 
					      :set IPType [ :tostr $2 ];
 | 
				
			||||||
    } else={
 | 
					    } else={
 | 
				
			||||||
      :local IPType "ipv4";
 | 
					      :global ExitError; $ExitError false $0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    :local IP [:resolve domain-name="$DomainName" type=$IPType];
 | 
					    :local ResolvedIP [:resolve domain-name="$DomainName" type=$IPType];
 | 
				
			||||||
    :return "$IP";
 | 
					    :return "$ResolvedIP";
 | 
				
			||||||
  } on-error={
 | 
					  } on-error={
 | 
				
			||||||
    return false;
 | 
					    :return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue