划分域名

问题描述 投票:0回答:5

有人实施对域名列表进行排序?

我已经看到一些应用程序将它们排序为扁平字符串,但问题是您最终将所有相关主机散布在一个域中:

a.me.com a.you.com B.Me.com b.you.com

一个标签的fqdns应该被视为主机名,并且可能单独分类,也许在顶部。

我正在寻找JavaScript和Java版本。

我也不知道此设计是否适合新的国际化域名。

我特别不知道Java和JavaScript,但是许多语言提供了某种数组数据结构,可以在词典上进行分类。 因此,就像您说的那样,将“ a.example.com”转换为{“ com”,“示例”,“ a”},然后让默认排序规则运行。 然后,词典形式将完全做您想要的。

如果您有本地域以及FQDN的列表,我同意您想将其分开。 任何没有段的东西都可以先滤除。 或者,您可以将它们全部解决到FQDN,然后对整个列表进行排序。

执行此操作的某些Python代码(应相当紧密地映射到JavaScript):
java javascript dns fqdn
5个回答
2
投票
hosts = ["a.foo.com", "b.foo.com", "foo.com", "c.bar.com"] split_hosts = [] for h in hosts: segments = h.split('.') segments.reverse() split_hosts.append(segments) split_hosts.sort() for segments in split_hosts: segments.reverse() print ".".join(segments)

this this Prints:

c.bar.com foo.com a.foo.com b.foo.com

基于tom的答案
...

hosts = new Array( "a.foo.com", "b.foo.com", "foo.com", "c.bar.com" ); //print("Unsorted:"); //for (host in hosts ) // print(hosts[host]); sorted_hosts = new Array(); split_hosts = new Array(); for(h in hosts) { segments = hosts[h].split('.'); segments.reverse(); split_hosts.push(segments); } split_hosts.sort() for(h in split_hosts) { split_hosts[h].reverse() sorted_hosts.push(split_hosts[h].join(".")) } //print("Sorted:"); //for (host in sorted_hosts ) // print(sorted_hosts[host]);
印刷语句在

2
投票

这是小型团队赢得的大型竞赛与80年代初期的小型战争的结果。 在英国,域名最初被订购,例如(假设的)英国“学术”(University of Leeds)。 这是大型订购 - 使您的出现更加容易。这也将使在URL中欺骗互联网站点变得更加困难。 当然,如今,该命令是小的,假设的URL将是'leeds.ac.uk'..

要明智地将相关域名分类在一起,您将必须首先通过最右边的组件(.com,.uk,.org)进行排序的效果,然后再进行下一个左侧,然后重复... Bala说),您必须做类似的事情,类似于将名称划分为左右。
    

这是在perl中完成的:

#!/usr/bin/perl -w use strict; my @hosts = qw( bar.org a.foo.com b.foo.com foo.com c.bar.com ); print join("\n", sort { $a = lc($a); $b = lc($b); if ($a eq $b) { return 0; } my @a = reverse(split(/\./, $a)); my @b = reverse(split(/\./, $b)); my $max = (scalar(@a), scalar(@b))[@a < @b]; for (my $i=0; $i < $max; $i++) { if (($i < @a) && ($i < @b)) { if (my $c = $a[$i] cmp $b[$i]) { return $c; } } else { return scalar(@a) <=> scalar(@b); } } return 0; } @hosts) . "\n";

1
投票

您可以将域名分为单个字段,并执行连续性。您可以创建一个域名对象以具有三个字段,并创建一个域名列表进行排序。对于这三个字段中的每个字段,都要做。最后,您有一系列与相关主机一起使用的域名列表。

我提出了使用array.prototype.sort()和ES6发电机的解决方案:


1
投票

here是Golang中排序域的样本:

0
投票
您可以将其重写为Java。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.