开发者

How to determine if two host names are in the same domain

开发者 https://www.devze.com 2023-03-02 17:56 出处:网络
How to write code to decide if two host name in same domain ? like : www.example.com an开发者_如何学Cd login.eample.com in same domain

How to write code to decide if two host name in same domain ?

like :

    www.example.com.us and login.exmaple.com.us in same domain
    x105.www.example.com and login.example.com in same domin

and even www.example.com and login.example.com.us in same domain if possible


Using perl since no language was mentioned, pardon any rust...

([^.]+\.[^.]+$)

that regex would give you the domain of the first instance as a captured string ($1). You could use that captured string, if this was say perl, like this to see if they match.

$firstHostName =~ /([^.]+\.[^.]+$)/;
if ($secondHostName =~ /$1$/) {
    print "same domain";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消