1616using Newtonsoft . Json . Linq ;
1717
1818using Zephyr . Directory . Ldap ;
19+ using System . Net ;
20+ using System . Net . Sockets ;
21+ using System . Text ;
1922
2023// Allows Lambda Function's JSON Input to be converted into a .NET class
2124[ assembly: LambdaSerializer ( typeof ( Amazon . Lambda . Serialization . Json . JsonSerializer ) ) ]
@@ -45,6 +48,7 @@ public static string parse_data(LdapObject data,List<string> headers){
4548
4649 return csv_string ;
4750 }
51+
4852 public static dynamic OutputConverter ( LdapResponse response , OutputType ? type ) {
4953 dynamic OutputObject = null ;
5054 if ( type == OutputType . Json ) {
@@ -70,6 +74,19 @@ public static dynamic OutputConverter(LdapResponse response, OutputType? type){
7074 }
7175 return OutputObject ;
7276 }
77+
78+ public static string GetServerIPAddress ( )
79+ {
80+ string localIP ;
81+ using ( Socket socket = new Socket ( AddressFamily . InterNetwork , SocketType . Dgram , 0 ) )
82+ {
83+ socket . Connect ( "8.8.8.8" , 80 ) ;
84+ IPEndPoint endpoint = socket . LocalEndPoint as IPEndPoint ;
85+ localIP = endpoint . Address . ToString ( ) ;
86+ }
87+ return localIP ;
88+ }
89+
7390 public static dynamic ProcessRequest ( LdapRequest request , ILambdaContext ctx )
7491 {
7592 bool isPing = request . Ping . HasValue ;
@@ -106,8 +123,10 @@ public static dynamic ProcessRequest(LdapRequest request, ILambdaContext ctx)
106123 System . Diagnostics . FileVersionInfo fvi = System . Diagnostics . FileVersionInfo . GetVersionInfo ( assembly . Location ) ;
107124 string version = fvi . FileVersion ;
108125 response . Message = "Hello From MyriAD (" + version + ")." ;
126+ response . Server = GetServerIPAddress ( ) ;
109127 if ( request . Ping == PingType . Echo )
110128 Console . WriteLine ( "Ping" ) ;
129+ output_data = response ;
111130 }
112131 else
113132 {
0 commit comments