Attempts to generate a valid IP address & port from the given string in format like this: "192.168.0.2:2503". If the process fails, then an empty string is returned.
294 {
295 string correct_ip_format;
296
298 potential_ip.
Split(
":", array_ip_and_port);
299
300 string ip_entries;
301 int port;
302
303 if(array_ip_and_port.Count() > 0)
304 {
305 ip_entries = array_ip_and_port.Get(0);
307 ip_entries.
Split(
".", array_ip);
308
309 string ip_string;
310 int ip_entries_count = array_ip.Count();
311
312 if (ip_entries_count <= 3 || ip_entries_count > 4)
313 return "";
314
315 for (int i = 0; i < 4; i++)
316 {
317 int ip_entry = array_ip.Get(i).ToInt();
318
319
320 if (ip_entry > 255 || ip_entry < 0)
321 ip_entry = 0;
322
323 ip_string = ip_string + ip_entry.ToString();
324
325 if (i < ip_entries_count - 1)
326 ip_string = ip_string + ".";
327 ;
328 }
329
330 correct_ip_format = ip_string;
331 }
332 else
333 {
334 ip_entries = "";
335 correct_ip_format = ip_entries;
336 }
337
338 if (correct_ip_format == "")
339 return "";
340
341
342
343 if(array_ip_and_port.Count() > 1)
344 {
345 port = array_ip_and_port.Get(1).ToInt();
346
347 if (port > 65535 | port < 0)
348 port = 2302;
349
350
351 if (port >= 0)
352 correct_ip_format = correct_ip_format + ":" + port.ToString();
353
354 }
355 else
356 {
357 port = 2302;
358 correct_ip_format = correct_ip_format + ":" + port.ToString();
359 }
360
361 return correct_ip_format;
362 }
array< string > TStringArray
void Split(string sample, out array< string > output)
Splits string into array of strings separated by 'sample'.