@@ -167,6 +167,34 @@ public bool PreparingScan
167167 OnPropertyChanged ( ) ;
168168 }
169169 }
170+
171+ private bool _displayErrorMessage ;
172+ public bool DisplayErrorMessage
173+ {
174+ get { return _displayErrorMessage ; }
175+ set
176+ {
177+ if ( value == _displayErrorMessage )
178+ return ;
179+
180+ _displayErrorMessage = value ;
181+ OnPropertyChanged ( ) ;
182+ }
183+ }
184+
185+ private string _errorMessage ;
186+ public string ErrorMessage
187+ {
188+ get { return _errorMessage ; }
189+ set
190+ {
191+ if ( value == _errorMessage )
192+ return ;
193+
194+ _errorMessage = value ;
195+ OnPropertyChanged ( ) ;
196+ }
197+ }
170198 #endregion
171199
172200 #region Constructor, Load settings
@@ -214,29 +242,33 @@ private void ScanAction()
214242 #region Methods
215243 private async void StartScan ( )
216244 {
245+ DisplayErrorMessage = false ;
246+ ErrorMessage = string . Empty ;
247+
217248 IsScanRunning = true ;
218249 PreparingScan = true ;
219250
220251 PortScanResult . Clear ( ) ;
221252
222253 cancellationTokenSource = new CancellationTokenSource ( ) ;
223254
224- string [ ] HostnameOrIPAddresses = HostnameOrIPAddress . Split ( ';' ) ;
255+ string [ ] hosts = HostnameOrIPAddress . Split ( ';' ) ;
225256
226257 List < Tuple < IPAddress , string > > hostData = new List < Tuple < IPAddress , string > > ( ) ;
227258
228- for ( int i = 0 ; i < HostnameOrIPAddresses . Length ; i ++ )
259+ for ( int i = 0 ; i < hosts . Length ; i ++ )
229260 {
230- string hostname = HostnameOrIPAddresses [ i ] ;
231- IPAddress . TryParse ( hostname , out IPAddress ipAddress ) ;
261+ string host = hosts [ i ] . Trim ( ) ;
262+ string hostname = string . Empty ;
263+ IPAddress . TryParse ( host , out IPAddress ipAddress ) ;
232264
233265 try
234266 {
235267 // Resolve DNS
236268 // Try to resolve the hostname
237269 if ( ipAddress == null )
238270 {
239- IPHostEntry ipHostEntry = await Dns . GetHostEntryAsync ( HostnameOrIPAddress ) ;
271+ IPHostEntry ipHostEntry = await Dns . GetHostEntryAsync ( host ) ;
240272
241273 foreach ( IPAddress ip in ipHostEntry . AddressList )
242274 {
@@ -261,18 +293,28 @@ private async void StartScan()
261293 continue ;
262294 }
263295 }
296+
297+ hostname = host ;
264298 }
265299 else
266300 {
267- IPHostEntry ipHostEntry = await Dns . GetHostEntryAsync ( ipAddress ) ;
301+ try
302+ {
303+ IPHostEntry ipHostEntry = await Dns . GetHostEntryAsync ( ipAddress ) ;
268304
269- if ( ipHostEntry != null )
270305 hostname = ipHostEntry . HostName ;
306+ }
307+ catch { }
271308 }
272309 }
273310 catch ( SocketException ) // This will catch DNS resolve errors
274311 {
275- await dialogCoordinator . ShowMessageAsync ( this , Application . Current . Resources [ "String_Header_DnsError" ] as string , Application . Current . Resources [ "String_CouldNotResolveHostnameMessage" ] as string , MessageDialogStyle . Affirmative , dialogSettings ) ;
312+ if ( ! string . IsNullOrEmpty ( ErrorMessage ) )
313+ ErrorMessage += Environment . NewLine ;
314+
315+ ErrorMessage += string . Format ( Application . Current . Resources [ "String_CouldNotResolveHostnameFor" ] as string , host ) ;
316+ DisplayErrorMessage = true ;
317+
276318 continue ;
277319 }
278320
@@ -282,7 +324,9 @@ private async void StartScan()
282324 if ( hostData . Count == 0 )
283325 {
284326 IsScanRunning = false ;
285- await dialogCoordinator . ShowMessageAsync ( this , Application . Current . Resources [ "String_Header_DnsError" ] as string , "Nothing to do" , MessageDialogStyle . Affirmative , dialogSettings ) ;
327+
328+ ErrorMessage += Environment . NewLine + Application . Current . Resources [ "String_NothingToDoCheckYourInput" ] as string ;
329+ DisplayErrorMessage = true ;
286330
287331 return ;
288332 }
@@ -318,17 +362,21 @@ private async void StartScan()
318362 catch ( Exception ex ) // This will catch any exception
319363 {
320364 IsScanRunning = false ;
321- await dialogCoordinator . ShowMessageAsync ( this , Application . Current . Resources [ "String_Header_Error" ] as string , ex . Message , MessageDialogStyle . Affirmative , dialogSettings ) ;
365+
366+ ErrorMessage = ex . Message ;
367+ DisplayErrorMessage = true ;
322368 }
323369 }
324370
325371 #region Events
326- private async void PortScanner_UserHasCanceled ( object sender , EventArgs e )
372+ private void PortScanner_UserHasCanceled ( object sender , EventArgs e )
327373 {
328374 CancelScan = false ;
329375 IsScanRunning = false ;
330376
331- await dialogCoordinator . ShowMessageAsync ( this , Application . Current . Resources [ "String_Header_CanceledByUser" ] as string , Application . Current . Resources [ "String_CanceledByUserMessage" ] as string , MessageDialogStyle . Affirmative , dialogSettings ) ;
377+ ErrorMessage = Application . Current . Resources [ "String_CanceledByUserMessage" ] as string ;
378+ DisplayErrorMessage = true ;
379+
332380 }
333381
334382 private void PortScanner_ProgressChanged ( object sender , ProgressChangedArgs e )
0 commit comments