Sponsored Content
Full Discussion: Check for valid hostnames
Top Forums Shell Programming and Scripting Check for valid hostnames Post 302974674 by RavinderSingh13 on Thursday 2nd of June 2016 04:34:14 AM
Old 06-02-2016
Quote:
Originally Posted by rahul2662
Hello,

I am trying to develop a script to check for valid hostnames. Below are the prerequisites for a valid hostname which I got from wiki :

Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname. Each label must be between 1 and 63 characters long, and the entire hostname (including the delimiting dots but not a trailing dot) has a maximum of 253 ASCII characters.

The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.

Could someone please help.

Thanks
Rahul
Hello Rahul,

Good to see you in forums Smilie. Regarding above query I would like to say it completely depends on the organization like they are really following the mentioned rules/guidelines or not. Why not do a ping test for each host and find out(means--> if a host is valid it will pass the test), please do let me know your thoughts on same.

Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check for a valid numeric input

Hi Folks, I'm using bash script. I would like to check whether input is a number or not.(Only positive numbers).. if space or non numeric is entered, it should say "invalid input". pls help.. thanks in adv. Br/// Vijay. (1 Reply)
Discussion started by: Vijayakumarpc
1 Replies

2. Shell Programming and Scripting

Check valid records in really big file with one commend..

Hi, I have a 5 gig file, no record terminators, field terminators are newline. The record length is 768 and I would like to check that every 768th byte is a newline and print out the byte position if it isn't. I would like to do this going either forward or backwards with one command if... (3 Replies)
Discussion started by: vtischuk@yahoo.
3 Replies

3. Shell Programming and Scripting

to check whether a directory or filename path is valid or not

the script on excution should take a directory path from useran a numric input and it should check indicate whether its write or not? if the cmmd sh<script-name>,dir/path.<500>" is greater than 500 in size should be copied to dir ,temp in pwd and display the mesage'files of 2000 bytes hav been... (4 Replies)
Discussion started by: arukr
4 Replies

4. Homework & Coursework Questions

Bash shell - Check if value is valid directory.

1. The problem statement, all variables and given/known data: The script usage will be as follows: library.third source_directory - Your script will display an appropriate error message and exit with status 3 if no parameters are given - Your script will display an appropriate error... (2 Replies)
Discussion started by: netmaster
2 Replies

5. Shell Programming and Scripting

how to check for valid password

I need to check if an account has a valid password. Would something like this work? read ACCNAME if grep -q "^$ACCNAME:\$6:" /etc/shadow; thenI noticed every entry in my shadow file that has a password starts with $6 ... it works for my current setup, but would it always work? I can't test... (4 Replies)
Discussion started by: ADay2Long
4 Replies

6. UNIX for Dummies Questions & Answers

How to check if file contains valid strings?

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (5 Replies)
Discussion started by: rtagarra
5 Replies

7. Shell Programming and Scripting

How to check the user input to be valid using shell script?

How to check the user input to be valid using shell script? The valid input is in the format like as follows. 1. It can only have r,w,x or a hyphen and nothing else. 2. ensure the r, w, x are in the correct order. for example: rwxr-xr-x is a valid format. Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies

8. Shell Programming and Scripting

Need a script to check if an argument is valid shell variable

I need a script that should print 'yes' if the argument is a valid shell variable name else 'No' if it is not a valid shell variable. A valid one begins with an alphabet or percentage (%) character and is followed by zero or more alphanumberic or percentage (%) characters. For example: $... (6 Replies)
Discussion started by: pingiliarjun
6 Replies

9. Shell Programming and Scripting

Check if a string is a valid timestamp in UNIX.

Hi all, I have date and time value in a string, I want to check if it is a valid date and time. Need help on this. Thanks (7 Replies)
Discussion started by: Pratiksha Mehra
7 Replies

10. Shell Programming and Scripting

Check if time format is valid

How can I validate if time (HH:MM:SS) argument is valid? I got this from web but I can't modify it to exit the script if the time argument is invalid. echo $1 | awk -F ':' '{ print ($1 <= 23 && $2 <= 59 && $3 <= 59) ? "good" : "bad" }' ex: ./script.ksh 12:34:21 = okay ./script.ksh... (10 Replies)
Discussion started by: erin00
10 Replies
Data::Validate::Domain(3pm)				User Contributed Perl Documentation			       Data::Validate::Domain(3pm)

NAME
Data::Validate::Domain - domain validation methods SYNOPSIS
use Data::Validate::Domain qw(is_domain); # as a function my $test = is_domain($suspect); die "$test is not a domain" unless defined $test; or my $test = is_domain($suspect,\%options); die "$test is not a domain" unless defined $test; # or as an object my $v = Data::Validate::Domain->new(%options); my $test = $v->is_domain($suspect); die "$test is not a domain" unless defined $test; DESCRIPTION
This module collects domain validation routines to make input validation, and untainting easier and more readable. All functions return an untainted value if the test passes, and undef if it fails. This means that you should always check for a defined status explicitly. Don't assume the return will be true. (e.g. is_username('0')) The value to test is always the first (and often only) argument. FUNCTIONS
new - constructor for OO usage $obj = Data::Validate::Domain->new(); my %options = ( domain_allow_underscore => 1, ); or my %options = ( domain_allow_single_label => 1, domain_private_tld => { 'privatetld1 ' => 1, 'privatetld2' => 1, } ); or my %options = ( domain_allow_single_label => 1, domain_private_tld => qr /^(?:privatetld1|privatetld2)$/, ); $obj = Data::Validate::Domain->new(%options); Description Returns a Data::Validator::Domain object. This lets you access all the validator function calls as methods without importing them into your namespace or using the clumsy Data::Validate::Domain::function_name() format. Options domain_allow_underscore According to RFC underscores are forbidden in "hostnames" but not "domainnames". By default is_domain,is_domain_label, and is_hostname will fail if you include underscores, setting this to a true value with authorize the use of underscores in all functions. domain_allow_single_label By default is_domain will fail if you ask it to verify a domain that only has a single label i.e. 'neely.cx' is good, but 'com' would fail. If you set this option to a true value then is_domain will allow single label domains through. This is most likely to be useful in combination with domain_private_tld domain_private_tld By default is_domain requires all domains to have a valid TLD (i.e. com, net, org, uk, etc), this is verified using the Net::Domain::TLD module. This behavior can be extended in two different ways. Either a hash reference can be supplied keyed by the additional TLD's, or you can supply a precompiled regular expression. NOTE: The TLD is normalized to the lower case form prior to the check being done. This is done only for the TLD check, and does not alter the output in any way. The hash reference example: domain_private_tld => { 'privatetld1 ' => 1, 'privatetld2' => 1, } The precompiled regualar expression example: domain_private_tld => qr /^(?:privatetld1|privatetld2)$/, Returns Returns a Data::Validate::Domain object is_domain - does the value look like a domain name? is_domain($value); or $obj->is_domain($value); or is_domain($value,\%options); or $obj->is_domain($value,\%options); Description Returns the untainted domain name if the test value appears to be a well-formed domain name. Note: See new for list of options and how those alter the behavior of this funciton. Arguments $value The potential domain to test. Returns Returns the untainted domain on success, undef on failure. Notes, Exceptions, & Bugs The function does not make any attempt to check whether a domain actually exists. It only looks to see that the format is appropriate. A dotted quad (such as 127.0.0.1) is not considered a domain and will return false. See Data::Validate::IP(3) for IP Validation. Performs a lookup via Net::Domain::TLD to verify that the TLD is valid for this domain. Does not consider "domain.com." a valid format. From RFC 952 A "name" (Net, Host, Gateway, or Domain name) is a text string up to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus sign (-), and period (.). Note that periods are only allowed when they serve to delimit components of "domain style names". No blank or space characters are permitted as part of a name. No distinction is made between upper and lower case. The first character must be an alpha character [Relaxed in RFC 1123] . The last character must not be a minus sign or period. From RFC 1035 labels 63 octets or less names 255 octets or less [snip] limit the label to 63 octets or less. To simplify implementations, the total length of a domain name (i.e., label octets and label length octets) is restricted to 255 octets or less. From RFC 1123 One aspect of host name syntax is hereby changed: the restriction on the first character is relaxed to allow either a letter or a digit. Host software MUST support this more liberal syntax. Host software MUST handle host names of up to 63 characters and SHOULD handle host names of up to 255 characters. is_hostname - does the value look like a hostname is_hostname($value); or $obj->is_hostname($value); or is_hostname($value,\%options); or $obj->is_hostname($value,\%options); Description Returns the untainted hostname if the test value appears to be a well-formed hostname. Note: See new for list of options and how those alter the behavior of this funciton. Arguments $value The potential hostname to test. Returns Returns the untainted hostname on success, undef on failure. Notes, Exceptions, & Bugs The function does not make any attempt to check whether a hostname actually exists. It only looks to see that the format is appropriate. Functions much like is_domain, except that it does not verify whether or not a valid TLD has been supplied and allows for there to only be a single component of the hostname (i.e www) Hostnames might or might not have a valid TLD attached. is_domain_label - does the value look like a domain label? is_domain_label($value); or $obj->is_domain_label($value); or is_domain_label($value,\%options); or $obj->is_domain_label($value,\%options); Description Returns the untainted domain label if the test value appears to be a well-formed domain label. Note: See new for list of options and how those alter the behavior of this funciton. Arguments $value The potential ip to test. Returns Returns the untainted domain label on success, undef on failure. Notes, Exceptions, & Bugs The function does not make any attempt to check whether a domain label actually exists. It only looks to see that the format is appropriate. SEE ALSO
[RFC 1034] [RFC 1035] [RFC 2181] [RFC 1123] Data::Validate(3) Data::Validate::IP(3) AUTHOR
Neil Neely <neil@neely.cx>. ACKNOWLEDGEMENTS
Thanks to Richard Sonnen <sonnen@richardsonnen.com> for writing the Data::Validate module. Thanks to Len Reed <lreed@levanta.com> for helping develop the options mechanism for Data::Validate modules. COPYRIGHT AND LICENSE
Copyright (c) 2005-2007 Neil Neely. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2010-12-29 Data::Validate::Domain(3pm)
All times are GMT -4. The time now is 09:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy