Validate domain name and ip address using regex in Rails - ruby-on-rails

I have tried build app like whois domain tool site.
On form have one text_field and I want field only input with domain name and ip address.
Example domain name : domain.com (without http://www. or https://www. or subdomain.)
Example Ip address : 4.4.4.4
I want validate using regex, I have create this regex (demo on rubular)
([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)
But that is not clean, www. or subdomain still accepted.

Check out this built in Ruby class Resolv::IPv4::Regex for IP validation
and this URI for domain names.

IP Adress:
/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}(?:\-([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))?$/

Related

Google Domains : create a custom domain based on a url path

I have a laravel projct deployed on a virtual machine on GCP and I need to create a subdomain for it based on its url , the url looks like this : 34.90.86.243/questions_bank/public/
but when I wanted to add the url to the data field on google domains I got confused on what type I should use to make this up to work.
see this image
so which type should I choose ? and if there is an other way to do it please tel me
You cannot create subdomains based upon URL paths (/questions_bank/public/).
DNS servers manage subdomain resource records based upon IP addresses (A and AAAA) and CNAMES (which resolve to A and AAAA resource records.
If your goal is to create a subdomain questionsbank as in questionsbank.example.com from the IP address 34.90.86.243, create an A with the Host name questionsbank, Type A, TTL 86400, Value 34.90.86.243.
In your webserver (Apache, Nginx, etc.) you can use URL Rewrite to map subdomains to URL paths.

How to name a "domain name" without TLD?

Is there a specific name for this kind of "domain name" : https://www.website ?
It's neither a domain name, a hostname, or an URL (because there's no TLD), neither a Second-level domain (because there's https://www.)
There is no specific name because there is nothing specific in your case.
https://www.website is an URL like any other ones, for hostname www.website which is on the TLD website, which is a gTLD, see https://www.iana.org/domains/root/db/website.html
There is nothing special here. You are probably not aware that website is a new TLD.

What's the difference between ftp#user and ftp://domain

What's the difference between these two URLs?
ftp://user#101.101.101.49/folder/request.js
ftp://test.net#ftp.website.net/folder/request.js
(Note that the IP is only for sample.)
Nothing is particularly different. The part before the # is your username. The part after the # is the remote host you're connecting to.
101.101.101.49 is by IP address
ftp.website.net is by hostname
The /folder/request.js is the path and filename you're looking to download.

Use of dot ( . ) after www. in the URL

I often visit a link!
But i have no idea what dot (.) represents in the URL.
What is use of dot (.) in the URL?
The dot (.) is the character that was defined to be the delimiter in domain names (see DNS).
It delimits the labels in a domain name.
The domain name www.google.com consists of three labels:
com (aka. the top-level domain)
google (aka. the second-level domain)
www (aka. the third-level domain, or subdomain)
The '.' is like a character which differentiates from the domains. like www.todaysfuture.in the '.' after www means the first domain is done. then it checks the next domain.
The best example is like your email ID
first is the email-ID
then is the '#' that means the account name is done
then comes gmail/yahoo/wtvr
then a '.' to finish the account type
then '.' com or in depending on the account
Web addresses, or Uniform Resource Locators, go backwards with more specific terms coming first (like real addresses).
So for www.google.com
com is the top level domain - it might be a global domain like .com or a country code like .uk, and some top level domains have sub divisions like .gov.uk and .co.uk.
google is the domain - this is the name you actually buy and route to your servers/services
www subdomain - these are optional, and can be used to distinguish different services running on the same server, so www.google.com would serve web pages while ftp.google.com might be an FTP service.
Note that the subdomain is often optional - google.com and most other servers will assume www as the default service or infer it from the protocol (the http:// bit).

Are there URI schemas for identifying IP addresses and domain names?

Is there a Unique Resource Identifier (URI) schema which allows to uniquely refer to IP addresses and domain names?
For example "http://8o.232.240.50" or "http://supersite.com" are not refering to IP address or a domain name, rather they are refering to some resource which can be accessed via HTTP protocol and it's HTTP path happens to include this given IP address or domain name. Therefore they are more of Unique Resource Locators (URL) than Unique Resource Identifiers (URI) or Unique Resource Names (URN).
What I am looking for are schemas like "mailto:someemai#something.com" for IP addresses and/or domain names.
Something like "domain:supersite.com" and "ip:80.232.240.50".
I could make up schemes like these for my own use, but I am wondering if there isn't something like this already out there. And if there isn't, why?
RFC 4501: Domain Name System Uniform Resource Identifiers
The Domain Name System (DNS) […] is a widely deployed system
used, among other things, to translate host names into IP addresses.
Several protocols use Uniform Resource Identifiers (URIs) to refer to
data. By defining a URI scheme for DNS data, the gap between these
two worlds is bridged. The DNS URI scheme defined here can be used
to reference any data stored in the DNS.
From the examples:
dns:www.example.org.?clAsS=IN;tYpE=A
dns:www.example.org
dns:simon.example.org?type=CERT
dns://192.168.1.1/ftp.example.org?type=A
dns:world%20wide%20web.example%5c.domain.org?TYPE=TXT
dns://fw.example.org/*.%20%00.example?type=TXT
According to the syntax, it should be possible to use the dnsauthority with an empty dnsname. dnsauthority takes a host as defined in RFC 3986, which says:
host = IP-literal / IPv4address / reg-name
So it should be possible to use domain names as well as IP addresses (an empty dnsname "is to be interpreted as the root itself").

Resources