@@ -18,11 +18,17 @@ public class DeviceImpl : DeviceBase
1818 private readonly IConfiguration _configuration ;
1919
2020 public string PrimaryNICName { get ; private set ; }
21+
2122 public string PrimaryIPv4Address { get ; private set ; }
2223 public string PrimaryIPv4DNS { get ; private set ; }
24+ public string PrimaryIPv4Gateway { get ; private set ; }
25+
26+ public string PrimaryIPv6Address { get ; private set ; }
27+ public string PrimaryIPv6DNS { get ; private set ; }
28+ public string PrimaryIPv6Gateway { get ; private set ; }
29+
2330 public string PrimaryMACAddress { get ; private set ; }
2431 public string PrimaryNTPAddress { get ; private set ; }
25- public string PrimaryIPv4Gateway { get ; private set ; }
2632
2733 public DeviceImpl ( IServer server , ILogger < DeviceImpl > logger , IConfiguration configuration )
2834 {
@@ -32,16 +38,25 @@ public DeviceImpl(IServer server, ILogger<DeviceImpl> logger, IConfiguration con
3238
3339 PrimaryNICName = _configuration . GetValue ( "DeviceImpl:PrimaryNICName" , "" ) ;
3440 if ( string . IsNullOrEmpty ( PrimaryNICName ) ) PrimaryNICName = GetPrimaryNICName ( ) ;
41+
3542 PrimaryIPv4Address = _configuration . GetValue ( "DeviceImpl:PrimaryIPv4Address" , "" ) ;
3643 if ( string . IsNullOrEmpty ( PrimaryIPv4Address ) ) PrimaryIPv4Address = GetPrimaryIPv4Address ( ) ;
3744 PrimaryIPv4DNS = _configuration . GetValue ( "DeviceImpl:PrimaryIPv4DNS" , "" ) ;
3845 if ( string . IsNullOrEmpty ( PrimaryIPv4DNS ) ) PrimaryIPv4DNS = GetPrimaryIPv4DNS ( ) ;
46+ PrimaryIPv4Gateway = _configuration . GetValue ( "DeviceImpl:PrimaryIPv4Gateway" , "" ) ;
47+ if ( string . IsNullOrEmpty ( PrimaryIPv4Gateway ) ) PrimaryIPv4Gateway = GetPrimaryIPv4Gateway ( ) ;
48+
49+ PrimaryIPv6Address = _configuration . GetValue ( "DeviceImpl:PrimaryIPv6Address" , "" ) ;
50+ if ( string . IsNullOrEmpty ( PrimaryIPv6Address ) ) PrimaryIPv6Address = GetPrimaryIPv6Address ( ) ;
51+ PrimaryIPv6DNS = _configuration . GetValue ( "DeviceImpl:PrimaryIPv6DNS" , "" ) ;
52+ if ( string . IsNullOrEmpty ( PrimaryIPv6DNS ) ) PrimaryIPv6DNS = GetPrimaryIPv6DNS ( ) ;
53+ PrimaryIPv6Gateway = _configuration . GetValue ( "DeviceImpl:PrimaryIPv6Gateway" , "" ) ;
54+ if ( string . IsNullOrEmpty ( PrimaryIPv6Gateway ) ) PrimaryIPv6Gateway = GetPrimaryIPv6Gateway ( ) ;
55+
3956 PrimaryMACAddress = _configuration . GetValue ( "DeviceImpl:PrimaryMACAddress" , "" ) ;
4057 if ( string . IsNullOrEmpty ( PrimaryMACAddress ) ) PrimaryMACAddress = GetPrimaryMACAddress ( ) ;
4158 PrimaryNTPAddress = _configuration . GetValue ( "DeviceImpl:PrimaryNTPAddress" , "" ) ;
4259 if ( string . IsNullOrEmpty ( PrimaryNTPAddress ) ) PrimaryNTPAddress = GetPrimaryNTPAddress ( ) ;
43- PrimaryIPv4Gateway = _configuration . GetValue ( "DeviceImpl:PrimaryIPv4Gateway" , "" ) ;
44- if ( string . IsNullOrEmpty ( PrimaryIPv4Gateway ) ) PrimaryIPv4Gateway = GetPrimaryIPv4Gateway ( ) ;
4560 }
4661
4762 public override GetCapabilitiesResponse GetCapabilities ( GetCapabilitiesRequest request )
@@ -167,6 +182,20 @@ public override GetNetworkInterfacesResponse GetNetworkInterfaces(GetNetworkInte
167182 } ,
168183 } ,
169184 Enabled = true ,
185+ } ,
186+ IPv6 = new IPv6NetworkInterface ( )
187+ {
188+ Config = new IPv6Configuration ( )
189+ {
190+ Manual = new PrefixedIPv6Address [ ]
191+ {
192+ new PrefixedIPv6Address ( )
193+ {
194+ Address = PrimaryIPv6Address
195+ }
196+ } ,
197+ } ,
198+ Enabled = true ,
170199 }
171200 } ,
172201 }
@@ -218,7 +247,8 @@ public override NetworkGateway GetNetworkDefaultGateway()
218247 {
219248 return new NetworkGateway ( )
220249 {
221- IPv4Address = new string [ ] { PrimaryIPv4Gateway }
250+ IPv4Address = new string [ ] { PrimaryIPv4Gateway } ,
251+ IPv6Address = new string [ ] { PrimaryIPv6Gateway }
222252 } ;
223253 }
224254
@@ -460,7 +490,7 @@ private static System.Net.NetworkInformation.NetworkInterface GetPrimaryNetworkI
460490
461491 public static string GetPrimaryIPv4Address ( )
462492 {
463- string ret = "0 .0.0.0 " ;
493+ string ret = "127 .0.0.1 " ;
464494 var nic = GetPrimaryNetworkInterface ( ) ;
465495 if ( nic != null )
466496 {
@@ -486,7 +516,7 @@ public static string GetPrimaryIPv4Address()
486516
487517 public static string GetPrimaryIPv4DNS ( )
488518 {
489- string ret = "0 .0.0.0 " ;
519+ string ret = "127 .0.0.1 " ;
490520 var nic = GetPrimaryNetworkInterface ( ) ;
491521 if ( nic != null )
492522 {
@@ -507,28 +537,84 @@ public static string GetPrimaryIPv4DNS()
507537 return ret ;
508538 }
509539
510- public static string GetPrimaryNTPAddress ( string ntp = "time.windows.com" )
540+ public static string GetPrimaryIPv4Gateway ( )
511541 {
512- string ret = "0 .0.0.0 " ;
513- var dnsHostEntry = System . Net . Dns . GetHostEntry ( ntp ) ;
514- if ( dnsHostEntry != null )
542+ string ret = "127 .0.0.1 " ;
543+ var nic = GetPrimaryNetworkInterface ( ) ;
544+ if ( nic != null )
515545 {
516- var addressList = dnsHostEntry . AddressList ;
517- if ( addressList != null )
546+ var nicProperties = nic . GetIPProperties ( ) ;
547+ if ( nicProperties != null )
518548 {
519- var ntpAddress = addressList . FirstOrDefault ( x => x . AddressFamily == System . Net . Sockets . AddressFamily . InterNetwork ) ;
520- if ( ntpAddress != null )
549+ var gatewayAddresses = nicProperties . GatewayAddresses ;
550+ if ( gatewayAddresses != null )
521551 {
522- ret = ntpAddress . ToString ( ) ;
552+ var gatewayAddress = gatewayAddresses . FirstOrDefault ( x => x . Address != null && x . Address . AddressFamily == System . Net . Sockets . AddressFamily . InterNetwork ) ;
553+ if ( gatewayAddress != null )
554+ {
555+ if ( gatewayAddress . Address != null )
556+ {
557+ ret = gatewayAddress . Address . ToString ( ) ;
558+ }
559+ }
523560 }
524561 }
525562 }
526563 return ret ;
527564 }
528565
529- public static string GetPrimaryIPv4Gateway ( )
566+ public static string GetPrimaryIPv6Address ( )
530567 {
531- string ret = "0.0.0.0" ;
568+ string ret = "::1" ;
569+ var nic = GetPrimaryNetworkInterface ( ) ;
570+ if ( nic != null )
571+ {
572+ var nicProperties = nic . GetIPProperties ( ) ;
573+ if ( nicProperties != null )
574+ {
575+ var unicastAddresses = nicProperties . UnicastAddresses ;
576+ if ( unicastAddresses != null )
577+ {
578+ var unicastAddress = unicastAddresses . FirstOrDefault ( x => x . Address != null && x . Address . AddressFamily == System . Net . Sockets . AddressFamily . InterNetworkV6 ) ;
579+ if ( unicastAddress != null )
580+ {
581+ if ( unicastAddress . Address != null )
582+ {
583+ ret = unicastAddress . Address . ToString ( ) ;
584+ }
585+ }
586+ }
587+ }
588+ }
589+ return ret ;
590+ }
591+
592+ public static string GetPrimaryIPv6DNS ( )
593+ {
594+ string ret = "::1" ;
595+ var nic = GetPrimaryNetworkInterface ( ) ;
596+ if ( nic != null )
597+ {
598+ var nicProperties = nic . GetIPProperties ( ) ;
599+ if ( nicProperties != null )
600+ {
601+ var dnsAddresses = nicProperties . DnsAddresses ;
602+ if ( dnsAddresses != null )
603+ {
604+ var dnsAddress = dnsAddresses . FirstOrDefault ( x => x . AddressFamily == System . Net . Sockets . AddressFamily . InterNetworkV6 ) ;
605+ if ( dnsAddress != null )
606+ {
607+ ret = dnsAddress . ToString ( ) ;
608+ }
609+ }
610+ }
611+ }
612+ return ret ;
613+ }
614+
615+ public static string GetPrimaryIPv6Gateway ( )
616+ {
617+ string ret = "::1" ;
532618 var nic = GetPrimaryNetworkInterface ( ) ;
533619 if ( nic != null )
534620 {
@@ -538,7 +624,7 @@ public static string GetPrimaryIPv4Gateway()
538624 var gatewayAddresses = nicProperties . GatewayAddresses ;
539625 if ( gatewayAddresses != null )
540626 {
541- var gatewayAddress = gatewayAddresses . FirstOrDefault ( x => x . Address != null && x . Address . AddressFamily == System . Net . Sockets . AddressFamily . InterNetwork ) ;
627+ var gatewayAddress = gatewayAddresses . FirstOrDefault ( x => x . Address != null && x . Address . AddressFamily == System . Net . Sockets . AddressFamily . InterNetworkV6 ) ;
542628 if ( gatewayAddress != null )
543629 {
544630 if ( gatewayAddress . Address != null )
@@ -552,6 +638,25 @@ public static string GetPrimaryIPv4Gateway()
552638 return ret ;
553639 }
554640
641+ public static string GetPrimaryNTPAddress ( string ntp = "time.windows.com" )
642+ {
643+ string ret = "127.0.0.1" ;
644+ var dnsHostEntry = System . Net . Dns . GetHostEntry ( ntp ) ;
645+ if ( dnsHostEntry != null )
646+ {
647+ var addressList = dnsHostEntry . AddressList ;
648+ if ( addressList != null )
649+ {
650+ var ntpAddress = addressList . FirstOrDefault ( x => x . AddressFamily == System . Net . Sockets . AddressFamily . InterNetwork ) ;
651+ if ( ntpAddress != null )
652+ {
653+ ret = ntpAddress . ToString ( ) ;
654+ }
655+ }
656+ }
657+ return ret ;
658+ }
659+
555660 public static string GetPrimaryMACAddress ( )
556661 {
557662 string ret = "00:00:00:00:00:00" ;
0 commit comments