PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Mimoza/Plugins/System Settings/NetworkPlugin/IPAddressTextBox.cs

#
C# | 2435 lines | 2007 code | 69 blank | 359 comment | 221 complexity | 04a746774845ade17d6d327012278f4a MD5 | raw file
Possible License(s): GPL-2.0
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. namespace Mimoza.Plugin.Forms
  7. {
  8. [
  9. DefaultProperty("Text"),
  10. DefaultEvent("TextChanged"),
  11. ]
  12. /// <summary>
  13. /// IPAddressTextBox
  14. /// Control to enter IP-Addresses manually
  15. /// Supports Binary and Decimal Notation
  16. /// Supports input of CIDR Notation (appending of Bitmask of Subnetmask devided by Slash)
  17. /// Support input of IP-Address in IPv6 format
  18. /// </summary>
  19. public class IPAddressTextBox : System.Windows.Forms.TextBox
  20. {
  21. /// <summary>
  22. /// Required designer variable.
  23. /// </summary>
  24. private System.ComponentModel.Container components = null;
  25. private IPNotation m_ipNotation = IPNotation.IPv4Decimal;
  26. private IPNotation m_newIPNotation = IPNotation.IPv4Decimal;
  27. private bool m_bOverwrite = true;
  28. private bool m_bPreventLeave = true;
  29. private System.Windows.Forms.ErrorProvider error;
  30. private Regex m_regexValidNumbers = new Regex("[0-9]");
  31. private ArrayList m_arlDelimeter = new ArrayList(new char[]{'.'});
  32. public enum IPNotation
  33. {
  34. IPv4Decimal, //192.168.000.001
  35. IPv4Binary, //11000000.10101000.00000000.00000001
  36. IPv4DecimalCIDR, //192.168.000.001/16
  37. IPv4BinaryCIDR, //11000000.10101000.00000000.00000001/16
  38. IPv6Hexadecimal, //0000:0000:0000:0000:00c0:00a8:0000:0001
  39. IPv6Binary, //0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000011000000:0000000010101000:0000000000000000:0000000000000001
  40. IPv6HexadecimalCIDR, //0000:0000:0000:0000:00c0:00a8:0000:0001/16
  41. IPv6BinaryCIDR, //0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000011000000:0000000010101000:0000000000000000:0000000000000001/16
  42. IPv6IPv4Decimal, //::192.168.000.001
  43. IPv6IPv4Binary, //::11000000.10101000.00000000.00000001
  44. IPv6IPv4DecimalCIDR, //::192.168.000.001/16
  45. IPv6IPv4BinaryCIDR //::11000000.10101000.00000000.00000001/16
  46. }
  47. /*
  48. switch(arg_value)
  49. {
  50. case IPNotation.IPv4Decimal:
  51. break;
  52. case IPNotation.IPv4DecimalCIDR:
  53. break;
  54. case IPNotation.IPv4Binary:
  55. break;
  56. case IPNotation.IPv4BinaryCIDR:
  57. break;
  58. case IPNotation.IPv6Hexadecimal:
  59. break;
  60. case IPNotation.IPv6HexadecimalCIDR:
  61. break;
  62. case IPNotation.IPv6Binary:
  63. break;
  64. case IPNotation.IPv6BinaryCIDR:
  65. break;
  66. case IPNotation.IPv6IPv4Decimal:
  67. break;
  68. case IPNotation.IPv6IPv4DecimalCIDR:
  69. break;
  70. case IPNotation.IPv6IPv4Binary:
  71. break;
  72. case IPNotation.IPv6IPv4BinaryCIDR:
  73. break;
  74. default:
  75. break;
  76. }
  77. */
  78. /// <summary>
  79. /// Constructor
  80. /// </summary>
  81. public IPAddressTextBox():base()
  82. {
  83. this.InitializeComponent();
  84. this.ResetText();
  85. }
  86. private void InitializeComponent()
  87. {
  88. this.error = new System.Windows.Forms.ErrorProvider();
  89. }
  90. /// <summary>
  91. /// Clean up any resources being used.
  92. /// </summary>
  93. protected override void Dispose( bool disposing )
  94. {
  95. if( disposing )
  96. {
  97. if( components != null )
  98. components.Dispose();
  99. }
  100. base.Dispose( disposing );
  101. }
  102. #region Properties
  103. #region Not allowed Properties from BaseClass
  104. /// <summary>
  105. /// Multiline is not allowed
  106. /// </summary>
  107. [
  108. Category("Behavior"),
  109. Description("Multiline is not allowed"),
  110. DefaultValue(false),
  111. Browsable(false)
  112. ]
  113. public override bool Multiline
  114. {
  115. get
  116. {
  117. return base.Multiline;
  118. }
  119. set
  120. {
  121. //base.Multiline = value;
  122. base.Multiline = false;
  123. }
  124. }
  125. [
  126. Category("Behavior"),
  127. Description("AllowDrop is not allowed"),
  128. DefaultValue(false),
  129. Browsable(false)
  130. ]
  131. public override bool AllowDrop
  132. {
  133. get
  134. {
  135. return base.AllowDrop;
  136. }
  137. set
  138. {
  139. //base.AllowDrop = value;
  140. base.AllowDrop = false;
  141. }
  142. }
  143. [
  144. Category("Behavior"),
  145. Description("AcceptsReturn is not allowed"),
  146. DefaultValue(false),
  147. Browsable(false)
  148. ]
  149. public new bool AcceptsReturn
  150. {
  151. get
  152. {
  153. return base.AcceptsReturn;
  154. }
  155. set
  156. {
  157. //base.AcceptsReturn = value;
  158. base.AcceptsReturn = false;
  159. }
  160. }
  161. [
  162. Category("Behavior"),
  163. Description("AcceptsTab is not allowed"),
  164. DefaultValue(false),
  165. Browsable(false)
  166. ]
  167. public new bool AcceptsTab
  168. {
  169. get
  170. {
  171. return base.AcceptsTab;
  172. }
  173. set
  174. {
  175. //base.AcceptTab = value;
  176. base.AcceptsTab = false;
  177. }
  178. }
  179. [
  180. Category("Behavior"),
  181. Description("CharacterCasing is not allowed"),
  182. DefaultValue(CharacterCasing.Normal),
  183. Browsable(false)
  184. ]
  185. public new CharacterCasing CharacterCasing
  186. {
  187. get
  188. {
  189. return base.CharacterCasing;
  190. }
  191. set
  192. {
  193. //base.CharacterCasing = value;
  194. base.CharacterCasing = CharacterCasing.Normal;
  195. }
  196. }
  197. [
  198. Category("Behavior"),
  199. Description("WordWrap is not allowed"),
  200. DefaultValue(true),
  201. Browsable(false)
  202. ]
  203. public new bool WordWrap
  204. {
  205. get
  206. {
  207. return base.WordWrap;
  208. }
  209. set
  210. {
  211. //base.WordWrap = value;
  212. base.WordWrap = true;
  213. }
  214. }
  215. /// <summary>
  216. /// Maxlength must not be changed by user
  217. /// </summary>
  218. [
  219. Category("Behavior"),
  220. Description("Specifies maximum length of a String. Change is not allowed"),
  221. DefaultValue(15),
  222. Browsable(false)
  223. ]
  224. public override int MaxLength
  225. {
  226. get
  227. {
  228. return base.MaxLength;
  229. }
  230. set
  231. {
  232. //base.MaxLength = value;
  233. base.MaxLength = this.Text.Length;
  234. }
  235. }
  236. #endregion // Not allowed Properties from BaseClass
  237. /// <summary>
  238. /// Specifies if IP-Address
  239. /// </summary>
  240. [
  241. Category("Appearance"),
  242. Description("Specifies the IP-Address"),
  243. DefaultValue(" . . . ")
  244. ]
  245. public override string Text
  246. {
  247. get
  248. {
  249. return base.Text;
  250. }
  251. set
  252. {
  253. try
  254. {
  255. if(IPAddressTextBox.ValidateIP(value, this.m_newIPNotation, this.m_arlDelimeter))
  256. base.Text = IPAddressTextBox.MakeValidSpaces(value, this.m_newIPNotation, this.m_arlDelimeter);
  257. }
  258. catch
  259. {
  260. }
  261. }
  262. }
  263. /// <summary>
  264. /// Specifies if Numbers should be overwritten
  265. /// </summary>
  266. [
  267. Category("Behavior"),
  268. Description("Specifies if Numbers should be overwritten"),
  269. DefaultValue(true)
  270. ]
  271. public bool OverWriteMode
  272. {
  273. get
  274. {
  275. return this.m_bOverwrite;
  276. }
  277. set
  278. {
  279. if(value!=this.m_bOverwrite)
  280. {
  281. this.m_bOverwrite = value;
  282. this.OnOverWriteChanged(value);
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// Prevents leaving of Control if there is an input-error
  288. /// </summary>
  289. [
  290. Category("Behavior"),
  291. Description("Prevents leaving of Control if there is an input-error"),
  292. DefaultValue(true)
  293. ]
  294. public bool PreventLeaveAtError
  295. {
  296. get
  297. {
  298. return this.m_bPreventLeave;
  299. }
  300. set
  301. {
  302. if(value!=this.m_bPreventLeave)
  303. {
  304. this.m_bPreventLeave = value;
  305. this.OnPreventLeaveChanged(value);
  306. }
  307. }
  308. }
  309. /// <summary>
  310. /// Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR
  311. /// </summary>
  312. [
  313. Category("Appearance"),
  314. Description("Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR"),
  315. DefaultValue(IPNotation.IPv4Decimal)
  316. ]
  317. public IPNotation Notation
  318. {
  319. get
  320. {
  321. return this.m_ipNotation;
  322. }
  323. set
  324. {
  325. if(value!=this.m_ipNotation)
  326. {
  327. try
  328. {
  329. this.m_newIPNotation = value;
  330. this.ChangeNotation(this.m_ipNotation, this.m_newIPNotation);
  331. this.m_ipNotation = this.m_newIPNotation;
  332. this.OnNotationChanged(this.m_newIPNotation);
  333. }
  334. catch(Exception LastError)
  335. {
  336. System.Diagnostics.Debug.WriteLine(LastError.Message);
  337. throw LastError;
  338. }
  339. }
  340. }
  341. }
  342. /// <summary>
  343. /// Specifies the Errorprovider that appears at invalid IPs
  344. /// </summary>
  345. [
  346. Category("Appearance"),
  347. Description("Specifies the Errorprovider that appears at invalid IPs"),
  348. DefaultValue(false)
  349. ]
  350. public ErrorProvider IPError
  351. {
  352. get
  353. {
  354. return this.error;
  355. }
  356. }
  357. #endregion //Properties
  358. #region Eventhandling
  359. /// <summary>
  360. /// Delegate for Notation-Events
  361. /// </summary>
  362. public delegate void NotationChangedEventHandler(IPNotation arg_newValue);
  363. /// <summary>
  364. /// Event called if AppearanceMode Notation is changed
  365. /// </summary>
  366. public event NotationChangedEventHandler NotationChanged;
  367. /// <summary>
  368. /// Delegate for Bool-Properties-Events
  369. /// </summary>
  370. public delegate void BoolPropertyChangedEventHandler(bool arg_bNewValue);
  371. /// <summary>
  372. /// Event called if BehaviorMode OverWriteMode is changed
  373. /// </summary>
  374. public event BoolPropertyChangedEventHandler OverWriteModeChanged;
  375. /// <summary>
  376. /// Event called if BehaviorMode PreventLeave is changed
  377. /// </summary>
  378. public event BoolPropertyChangedEventHandler PreventLeaveChanged;
  379. /// <summary>
  380. /// Occures when Appearance-Mode Notation was changed
  381. /// </summary>
  382. /// <param name="arg_Value">Value, Input IP-Address notation</param>
  383. protected virtual void OnNotationChanged(IPNotation arg_Value)
  384. {
  385. if(this.NotationChanged!=null)
  386. this.NotationChanged(arg_Value);
  387. }
  388. private void ChangeNotation(IPNotation arg_oldValue, IPNotation arg_newValue)
  389. {
  390. string sTo = "";
  391. ArrayList arlFrom = new ArrayList(this.Text.Replace(" ","").Split((char[])this.m_arlDelimeter.ToArray(typeof(char))));
  392. switch(arg_newValue)
  393. {
  394. case IPNotation.IPv4Decimal:
  395. this.m_regexValidNumbers = new Regex("[0-9]");
  396. this.m_arlDelimeter = new ArrayList(new char[]{'.'});
  397. break;
  398. case IPNotation.IPv4DecimalCIDR:
  399. this.m_regexValidNumbers = new Regex("[0-9]");
  400. this.m_arlDelimeter = new ArrayList(new char[]{'.','/'});
  401. break;
  402. case IPNotation.IPv4Binary:
  403. this.m_regexValidNumbers = new Regex("[01]");
  404. this.m_arlDelimeter = new ArrayList(new char[]{'.'});
  405. break;
  406. case IPNotation.IPv4BinaryCIDR:
  407. this.m_regexValidNumbers = new Regex("[01]");
  408. this.m_arlDelimeter = new ArrayList(new char[]{'.','/'});
  409. break;
  410. case IPNotation.IPv6Hexadecimal:
  411. this.m_regexValidNumbers = new Regex("[0-9a-fA-F]");
  412. this.m_arlDelimeter = new ArrayList(new char[]{':'});
  413. break;
  414. case IPNotation.IPv6HexadecimalCIDR:
  415. this.m_regexValidNumbers = new Regex("[0-9a-fA-F]");
  416. this.m_arlDelimeter = new ArrayList(new char[]{':','/'});
  417. break;
  418. case IPNotation.IPv6Binary:
  419. this.m_regexValidNumbers = new Regex("[01]");
  420. this.m_arlDelimeter = new ArrayList(new char[]{':'});
  421. break;
  422. case IPNotation.IPv6BinaryCIDR:
  423. this.m_regexValidNumbers = new Regex("[01]");
  424. this.m_arlDelimeter = new ArrayList(new char[]{':','/'});
  425. break;
  426. case IPNotation.IPv6IPv4Decimal:
  427. this.m_regexValidNumbers = new Regex("[0-9]");
  428. this.m_arlDelimeter = new ArrayList(new char[]{':','.'});
  429. break;
  430. case IPNotation.IPv6IPv4DecimalCIDR:
  431. this.m_regexValidNumbers = new Regex("[0-9]");
  432. this.m_arlDelimeter = new ArrayList(new char[]{':','.','/'});
  433. break;
  434. case IPNotation.IPv6IPv4Binary:
  435. this.m_regexValidNumbers = new Regex("[01]");
  436. this.m_arlDelimeter = new ArrayList(new char[]{':','.'});
  437. break;
  438. case IPNotation.IPv6IPv4BinaryCIDR:
  439. this.m_regexValidNumbers = new Regex("[01]");
  440. this.m_arlDelimeter = new ArrayList(new char[]{':','.','/'});
  441. break;
  442. default:
  443. break;
  444. }
  445. switch(arg_oldValue)
  446. {
  447. case IPNotation.IPv4Decimal:
  448. switch(arg_newValue)
  449. {
  450. case IPNotation.IPv4Decimal:
  451. break;
  452. case IPNotation.IPv4DecimalCIDR:
  453. for(int i=0; i<arlFrom.Count; i++)
  454. {
  455. sTo += arlFrom[i].ToString() +
  456. //Add Slash if its the last IPPart, els add a dot
  457. (i==arlFrom.Count-1?"/ ":".");
  458. }
  459. break;
  460. case IPNotation.IPv4Binary:
  461. for(int i=0; i<arlFrom.Count; i++)
  462. {
  463. //Convert Decimal to Binary
  464. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  465. //Add Dot if its not the last IPPart, else add nothing
  466. (i==arlFrom.Count-1?"":".");
  467. }
  468. break;
  469. case IPNotation.IPv4BinaryCIDR:
  470. for(int i=0; i<arlFrom.Count; i++)
  471. {
  472. //Convert Decimal to Binary
  473. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  474. //Add Slash if its the last IPPart, else add a dot
  475. (i==arlFrom.Count-1?"/ ":".");
  476. }
  477. break;
  478. case IPNotation.IPv6Hexadecimal:
  479. sTo = "0000:0000:0000:0000:";
  480. for(int i=0; i<arlFrom.Count; i++)
  481. {
  482. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  483. }
  484. break;
  485. case IPNotation.IPv6HexadecimalCIDR:
  486. sTo = "0000:0000:0000:0000:";
  487. for(int i=0; i<arlFrom.Count; i++)
  488. {
  489. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  490. }
  491. break;
  492. case IPNotation.IPv6Binary:
  493. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  494. for(int i=0; i<arlFrom.Count; i++)
  495. {
  496. sTo += this.Dec2Bin(arlFrom[i].ToString(), true) + (i==arlFrom.Count-1?"":":");
  497. }
  498. break;
  499. case IPNotation.IPv6BinaryCIDR:
  500. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  501. for(int i=0; i<arlFrom.Count; i++)
  502. {
  503. sTo += this.Dec2Bin(arlFrom[i].ToString(), true) + (i==arlFrom.Count-1?"/ ":":");
  504. }
  505. break;
  506. case IPNotation.IPv6IPv4Decimal:
  507. sTo = "::";
  508. for(int i=0; i<arlFrom.Count; i++)
  509. {
  510. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"":".");
  511. }
  512. break;
  513. case IPNotation.IPv6IPv4DecimalCIDR:
  514. sTo = "::";
  515. for(int i=0; i<arlFrom.Count; i++)
  516. {
  517. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":".");
  518. }
  519. break;
  520. case IPNotation.IPv6IPv4Binary:
  521. sTo = "::";
  522. for(int i=0; i<arlFrom.Count; i++)
  523. {
  524. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  525. }
  526. break;
  527. case IPNotation.IPv6IPv4BinaryCIDR:
  528. sTo = "::";
  529. for(int i=0; i<arlFrom.Count; i++)
  530. {
  531. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  532. }
  533. break;
  534. default:
  535. break;
  536. }
  537. break;
  538. case IPNotation.IPv4DecimalCIDR:
  539. switch(arg_newValue)
  540. {
  541. case IPNotation.IPv4Decimal:
  542. //do not use the last Item, its the Subnetmask
  543. for(int i=0; i<arlFrom.Count-1; i++)
  544. {
  545. sTo += arlFrom[i].ToString() +
  546. //Add Dot if its not the last IPPart, else add nothing
  547. (i==arlFrom.Count-2?"":".");
  548. }
  549. break;
  550. case IPNotation.IPv4DecimalCIDR:
  551. break;
  552. case IPNotation.IPv4Binary:
  553. //do not use the last Item, its the Subnetmask
  554. for(int i=0; i<arlFrom.Count-1; i++)
  555. {
  556. //Convert Decimal to Binary
  557. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  558. //Add Dot if its not the last IPPart, else add nothing
  559. (i==arlFrom.Count-2?"":".");
  560. }
  561. break;
  562. case IPNotation.IPv4BinaryCIDR:
  563. //do not use the last Item, its the Subnetmask
  564. for(int i=0; i<arlFrom.Count-1; i++)
  565. {
  566. //Convert Decimal to Binary
  567. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  568. //Add Dot if its not the last IPPart, else add nothing
  569. (i==arlFrom.Count-2?"":".");
  570. }
  571. //Add Subnetmask
  572. sTo += "/" + arlFrom[arlFrom.Count-1];
  573. break;
  574. case IPNotation.IPv6Hexadecimal:
  575. sTo = "0000:0000:0000:0000:";
  576. for(int i=0; i<arlFrom.Count-1; i++)
  577. {
  578. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  579. }
  580. break;
  581. case IPNotation.IPv6HexadecimalCIDR:
  582. sTo = "0000:0000:0000:0000:";
  583. for(int i=0; i<arlFrom.Count-1; i++)
  584. {
  585. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  586. }
  587. sTo += "/" + arlFrom[arlFrom.Count-1];
  588. break;
  589. case IPNotation.IPv6Binary:
  590. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  591. for(int i=0; i<arlFrom.Count-1; i++)
  592. {
  593. sTo += this.Dec2Bin(arlFrom[i].ToString(),true) + (i==arlFrom.Count-2?"":":");
  594. }
  595. break;
  596. case IPNotation.IPv6BinaryCIDR:
  597. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  598. for(int i=0; i<arlFrom.Count-1; i++)
  599. {
  600. sTo += this.Dec2Bin(arlFrom[i].ToString(),true) + (i==arlFrom.Count-2?"":":");
  601. }
  602. sTo += "/" + arlFrom[arlFrom.Count-1];
  603. break;
  604. case IPNotation.IPv6IPv4Decimal:
  605. sTo = "::";
  606. for(int i=0; i<arlFrom.Count-1; i++)
  607. {
  608. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  609. }
  610. break;
  611. case IPNotation.IPv6IPv4DecimalCIDR:
  612. sTo = "::";
  613. for(int i=0; i<arlFrom.Count-1; i++)
  614. {
  615. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  616. }
  617. sTo += "/" + arlFrom[arlFrom.Count-1];
  618. break;
  619. case IPNotation.IPv6IPv4Binary:
  620. sTo = "::";
  621. for(int i=0; i<arlFrom.Count-1; i++)
  622. {
  623. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  624. }
  625. break;
  626. case IPNotation.IPv6IPv4BinaryCIDR:
  627. sTo = "::";
  628. for(int i=0; i<arlFrom.Count-1; i++)
  629. {
  630. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  631. }
  632. sTo += "/" + arlFrom[arlFrom.Count-1];
  633. break;
  634. default:
  635. break;
  636. }
  637. break;
  638. case IPNotation.IPv4Binary:
  639. switch(arg_newValue)
  640. {
  641. case IPNotation.IPv4Decimal:
  642. for(int i=0; i<arlFrom.Count; i++)
  643. {
  644. //Convert Binary to Decimal
  645. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  646. //Add Dot if its not the last IPPart, else add nothing
  647. (i==arlFrom.Count-1?"":".");
  648. }
  649. break;
  650. case IPNotation.IPv4DecimalCIDR:
  651. for(int i=0; i<arlFrom.Count; i++)
  652. {
  653. //Convert Binary to Decimal
  654. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  655. //Add Slash if its the last IPPart, els add a dot
  656. (i==arlFrom.Count-1?"/ ":".");
  657. }
  658. break;
  659. case IPNotation.IPv4Binary:
  660. break;
  661. case IPNotation.IPv4BinaryCIDR:
  662. for(int i=0; i<arlFrom.Count; i++)
  663. {
  664. sTo += arlFrom[i].ToString() +
  665. //Add Slash if its the last IPPart, else add a dot
  666. (i==arlFrom.Count-1?"/ ":".");
  667. }
  668. break;
  669. case IPNotation.IPv6Hexadecimal:
  670. sTo = "0000:0000:0000:0000:";
  671. for(int i=0; i<arlFrom.Count; i++)
  672. {
  673. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  674. }
  675. break;
  676. case IPNotation.IPv6HexadecimalCIDR:
  677. sTo = "0000:0000:0000:0000:";
  678. for(int i=0; i<arlFrom.Count; i++)
  679. {
  680. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  681. }
  682. break;
  683. case IPNotation.IPv6Binary:
  684. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  685. for(int i=0; i<arlFrom.Count; i++)
  686. {
  687. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-1?"":":");
  688. }
  689. break;
  690. case IPNotation.IPv6BinaryCIDR:
  691. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  692. for(int i=0; i<arlFrom.Count; i++)
  693. {
  694. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":":");
  695. }
  696. break;
  697. case IPNotation.IPv6IPv4Decimal:
  698. sTo = "::";
  699. for(int i=0; i<arlFrom.Count; i++)
  700. {
  701. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  702. }
  703. break;
  704. case IPNotation.IPv6IPv4DecimalCIDR:
  705. sTo = "::";
  706. for(int i=0; i<arlFrom.Count; i++)
  707. {
  708. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  709. }
  710. break;
  711. case IPNotation.IPv6IPv4Binary:
  712. sTo = "::";
  713. for(int i=0; i<arlFrom.Count; i++)
  714. {
  715. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"":".");
  716. }
  717. break;
  718. case IPNotation.IPv6IPv4BinaryCIDR:
  719. sTo = "::";
  720. for(int i=0; i<arlFrom.Count; i++)
  721. {
  722. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":".");
  723. }
  724. break;
  725. default:
  726. break;
  727. }
  728. break;
  729. case IPNotation.IPv4BinaryCIDR:
  730. switch(arg_newValue)
  731. {
  732. case IPNotation.IPv4Decimal:
  733. //do not use the last Item, its the Subnetmask
  734. for(int i=0; i<arlFrom.Count-1; i++)
  735. {
  736. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  737. //Add Dot if its not the last IPPart, else add nothing
  738. (i==arlFrom.Count-2?"":".");
  739. }
  740. break;
  741. case IPNotation.IPv4DecimalCIDR:
  742. //do not use the last Item, its the Subnetmask
  743. for(int i=0; i<arlFrom.Count-1; i++)
  744. {
  745. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  746. //Add Dot if its not the last IPPart, else add nothing
  747. (i==arlFrom.Count-2?"":".");
  748. }
  749. //Add Subnetmask
  750. sTo += "/" + arlFrom[arlFrom.Count-1];
  751. break;
  752. case IPNotation.IPv4Binary:
  753. //do not use the last Item, its the Subnetmask
  754. for(int i=0; i<arlFrom.Count-1; i++)
  755. {
  756. sTo += arlFrom[i].ToString() +
  757. //Add Dot if its not the last IPPart, else add nothing
  758. (i==arlFrom.Count-2?"":".");
  759. }
  760. break;
  761. case IPNotation.IPv4BinaryCIDR:
  762. break;
  763. case IPNotation.IPv6Hexadecimal:
  764. sTo = "0000:0000:0000:0000:";
  765. for(int i=0; i<arlFrom.Count-1; i++)
  766. {
  767. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  768. }
  769. break;
  770. case IPNotation.IPv6HexadecimalCIDR:
  771. sTo = "0000:0000:0000:0000:";
  772. for(int i=0; i<arlFrom.Count-1; i++)
  773. {
  774. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  775. }
  776. sTo += "/" + arlFrom[arlFrom.Count-1];
  777. break;
  778. case IPNotation.IPv6Binary:
  779. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  780. for(int i=0; i<arlFrom.Count-1; i++)
  781. {
  782. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  783. }
  784. break;
  785. case IPNotation.IPv6BinaryCIDR:
  786. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  787. for(int i=0; i<arlFrom.Count-1; i++)
  788. {
  789. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  790. }
  791. sTo += "/" + arlFrom[arlFrom.Count-1];
  792. break;
  793. case IPNotation.IPv6IPv4Decimal:
  794. sTo = "::";
  795. for(int i=0; i<arlFrom.Count-1; i++)
  796. {
  797. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  798. }
  799. break;
  800. case IPNotation.IPv6IPv4DecimalCIDR:
  801. sTo = "::";
  802. for(int i=0; i<arlFrom.Count-1; i++)
  803. {
  804. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  805. }
  806. sTo += "/" + arlFrom[arlFrom.Count-1];
  807. break;
  808. case IPNotation.IPv6IPv4Binary:
  809. sTo = "::";
  810. for(int i=0; i<arlFrom.Count-1; i++)
  811. {
  812. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  813. }
  814. break;
  815. case IPNotation.IPv6IPv4BinaryCIDR:
  816. sTo = "::";
  817. for(int i=0; i<arlFrom.Count-1; i++)
  818. {
  819. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  820. }
  821. sTo += "/" + arlFrom[arlFrom.Count-1];
  822. break;
  823. default:
  824. break;
  825. }
  826. break;
  827. case IPNotation.IPv6Hexadecimal:
  828. switch(arg_newValue)
  829. {
  830. case IPNotation.IPv4Decimal:
  831. //do not use the 1st 4 elements (IPv4 has only 4 elements)
  832. for(int i=4; i<arlFrom.Count; i++)
  833. {
  834. //Convert Hexadecimal to Decimal
  835. sTo += this.Hex2Dec(arlFrom[i].ToString()) +
  836. //Add Dot if its not the last IPPart, else add nothing
  837. (i==arlFrom.Count-1?"":".");
  838. }
  839. break;
  840. case IPNotation.IPv4DecimalCIDR:
  841. //do not use the 1st 4 elements
  842. for(int i=4; i<arlFrom.Count; i++)
  843. {
  844. sTo += this.Hex2Dec(arlFrom[i].ToString()) +
  845. //Add Slash if its the last IPPart, els add a dot
  846. (i==arlFrom.Count-1?"/ ":".");
  847. }
  848. break;
  849. case IPNotation.IPv4Binary:
  850. //do not use the 1st 4 elements
  851. for(int i=4; i<arlFrom.Count; i++)
  852. {
  853. //Convert Hexadecimal to Binary
  854. sTo += this.Hex2Bin(arlFrom[i].ToString(), false) +
  855. //Add Dot if its not the last IPPart, else add nothing
  856. (i==arlFrom.Count-1?"":".");
  857. }
  858. break;
  859. case IPNotation.IPv4BinaryCIDR:
  860. //do not use the 1st 4 elements
  861. for(int i=4; i<arlFrom.Count; i++)
  862. {
  863. sTo += this.Hex2Bin(arlFrom[i].ToString(), false) +
  864. //Add Slash if its the last IPPart, else add a dot
  865. (i==arlFrom.Count-1?"/ ":".");
  866. }
  867. break;
  868. case IPNotation.IPv6Hexadecimal:
  869. break;
  870. case IPNotation.IPv6HexadecimalCIDR:
  871. for(int i=0; i<arlFrom.Count; i++)
  872. {
  873. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":":");
  874. }
  875. break;
  876. case IPNotation.IPv6Binary:
  877. for(int i=0; i<arlFrom.Count; i++)
  878. {
  879. sTo += this.Hex2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  880. }
  881. break;
  882. case IPNotation.IPv6BinaryCIDR:
  883. for(int i=0; i<arlFrom.Count; i++)
  884. {
  885. sTo += this.Hex2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  886. }
  887. break;
  888. case IPNotation.IPv6IPv4Decimal:
  889. sTo = "::";
  890. for(int i=4; i<arlFrom.Count; i++)
  891. {
  892. sTo += this.Hex2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  893. }
  894. break;
  895. case IPNotation.IPv6IPv4DecimalCIDR:
  896. sTo = "::";
  897. for(int i=4; i<arlFrom.Count; i++)
  898. {
  899. sTo += this.Hex2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  900. }
  901. break;
  902. case IPNotation.IPv6IPv4Binary:
  903. sTo = "::";
  904. for(int i=4; i<arlFrom.Count; i++)
  905. {
  906. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  907. }
  908. break;
  909. case IPNotation.IPv6IPv4BinaryCIDR:
  910. sTo = "::";
  911. for(int i=4; i<arlFrom.Count; i++)
  912. {
  913. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  914. }
  915. break;
  916. default:
  917. break;
  918. }
  919. break;
  920. case IPNotation.IPv6HexadecimalCIDR:
  921. switch(arg_newValue)
  922. {
  923. case IPNotation.IPv4Decimal:
  924. //do not use the last Item, its the Subnetmask
  925. //do not use the 1st 4 elements
  926. for(int i=4; i<arlFrom.Count-1; i++)
  927. {
  928. sTo += this.Hex2Dec(arlFrom[i].ToString()) +
  929. //Add Dot if its not the last IPPart, else add nothing
  930. (i==arlFrom.Count-2?"":".");
  931. }
  932. break;
  933. case IPNotation.IPv4DecimalCIDR:
  934. //do not use the last Item, its the Subnetmask
  935. for(int i=4; i<arlFrom.Count-1; i++)
  936. {
  937. //Convert Hexadecimal to Decimal
  938. sTo += this.Hex2Dec(arlFrom[i].ToString()) +
  939. //Add Dot if its not the last IPPart, else add nothing
  940. (i==arlFrom.Count-2?"":".");
  941. }
  942. //Add Subnetmask
  943. sTo += "/" + arlFrom[arlFrom.Count-1];
  944. break;
  945. case IPNotation.IPv4Binary:
  946. //do not use the last Item, its the Subnetmask
  947. for(int i=4; i<arlFrom.Count-1; i++)
  948. {
  949. sTo += this.Hex2Bin(arlFrom[i].ToString(), false) +
  950. //Add Dot if its not the last IPPart, else add nothing
  951. (i==arlFrom.Count-2?"":".");
  952. }
  953. break;
  954. case IPNotation.IPv4BinaryCIDR:
  955. //do not use the last Item, its the Subnetmask
  956. for(int i=4; i<arlFrom.Count-1; i++)
  957. {
  958. sTo += this.Hex2Bin(arlFrom[i].ToString(), false) +
  959. //Add Dot if its not the last IPPart, else add nothing
  960. (i==arlFrom.Count-2?"":".");
  961. }
  962. //Add Subnetmask
  963. sTo += "/" + arlFrom[arlFrom.Count-1];
  964. break;
  965. case IPNotation.IPv6Hexadecimal:
  966. for(int i=0; i<arlFrom.Count-1; i++)
  967. {
  968. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  969. }
  970. break;
  971. case IPNotation.IPv6HexadecimalCIDR:
  972. break;
  973. case IPNotation.IPv6Binary:
  974. for(int i=0; i<arlFrom.Count-1; i++)
  975. {
  976. sTo += this.Hex2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  977. }
  978. break;
  979. case IPNotation.IPv6BinaryCIDR:
  980. for(int i=0; i<arlFrom.Count-1; i++)
  981. {
  982. sTo += this.Hex2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  983. }
  984. sTo += "/" + arlFrom[arlFrom.Count-1];
  985. break;
  986. case IPNotation.IPv6IPv4Decimal:
  987. sTo = "::";
  988. for(int i=4; i<arlFrom.Count-1; i++)
  989. {
  990. sTo += this.Hex2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  991. }
  992. break;
  993. case IPNotation.IPv6IPv4DecimalCIDR:
  994. sTo = "::";
  995. for(int i=4; i<arlFrom.Count-1; i++)
  996. {
  997. sTo += this.Hex2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  998. }
  999. sTo += "/" + arlFrom[arlFrom.Count-1];
  1000. break;
  1001. case IPNotation.IPv6IPv4Binary:
  1002. sTo = "::";
  1003. for(int i=4; i<arlFrom.Count-1; i++)
  1004. {
  1005. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1006. }
  1007. break;
  1008. case IPNotation.IPv6IPv4BinaryCIDR:
  1009. sTo = "::";
  1010. for(int i=4; i<arlFrom.Count-1; i++)
  1011. {
  1012. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1013. }
  1014. sTo += "/" + arlFrom[arlFrom.Count-1];
  1015. break;
  1016. default:
  1017. break;
  1018. }
  1019. break;
  1020. case IPNotation.IPv6Binary:
  1021. switch(arg_newValue)
  1022. {
  1023. case IPNotation.IPv4Decimal:
  1024. //do not use the 1st 4 elements
  1025. for(int i=4; i<arlFrom.Count; i++)
  1026. {
  1027. //Convert Binary to Decimal
  1028. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1029. //Add Dot if its not the last IPPart, else add nothing
  1030. (i==arlFrom.Count-1?"":".");
  1031. }
  1032. break;
  1033. case IPNotation.IPv4DecimalCIDR:
  1034. //do not use the 1st 4 elements
  1035. for(int i=4; i<arlFrom.Count; i++)
  1036. {
  1037. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1038. //Add Slash if its the last IPPart, els add a dot
  1039. (i==arlFrom.Count-1?"/ ":".");
  1040. }
  1041. break;
  1042. case IPNotation.IPv4Binary:
  1043. //do not use the 1st 4 elements
  1044. for(int i=4; i<arlFrom.Count; i++)
  1045. {
  1046. //convert from IPv6 Binary to IPv4 Binary
  1047. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1048. //Add Dot if its not the last IPPart, else add nothing
  1049. (i==arlFrom.Count-1?"":".");
  1050. }
  1051. break;
  1052. case IPNotation.IPv4BinaryCIDR:
  1053. //do not use the 1st 4 elements
  1054. for(int i=4; i<arlFrom.Count; i++)
  1055. {
  1056. //convert from IPv6 Binary to IPv4 Binary
  1057. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1058. //Add Slash if its the last IPPart, else add a dot
  1059. (i==arlFrom.Count-1?"/ ":".");
  1060. }
  1061. break;
  1062. case IPNotation.IPv6Hexadecimal:
  1063. for(int i=0; i<arlFrom.Count; i++)
  1064. {
  1065. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  1066. }
  1067. break;
  1068. case IPNotation.IPv6HexadecimalCIDR:
  1069. for(int i=0; i<arlFrom.Count; i++)
  1070. {
  1071. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  1072. }
  1073. break;
  1074. case IPNotation.IPv6Binary:
  1075. break;
  1076. case IPNotation.IPv6BinaryCIDR:
  1077. for(int i=0; i<arlFrom.Count; i++)
  1078. {
  1079. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":":");
  1080. }
  1081. break;
  1082. case IPNotation.IPv6IPv4Decimal:
  1083. sTo = "::";
  1084. for(int i=4; i<arlFrom.Count; i++)
  1085. {
  1086. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  1087. }
  1088. break;
  1089. case IPNotation.IPv6IPv4DecimalCIDR:
  1090. sTo = "::";
  1091. for(int i=4; i<arlFrom.Count; i++)
  1092. {
  1093. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  1094. }
  1095. break;
  1096. case IPNotation.IPv6IPv4Binary:
  1097. sTo = "::";
  1098. for(int i=4; i<arlFrom.Count; i++)
  1099. {
  1100. //convert from IPv6 Binary to IPv4 Binary
  1101. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1102. (i==arlFrom.Count-1?"":".");
  1103. }
  1104. break;
  1105. case IPNotation.IPv6IPv4BinaryCIDR:
  1106. sTo = "::";
  1107. for(int i=4; i<arlFrom.Count; i++)
  1108. {
  1109. //convert from IPv6 Binary to IPv4 Binary
  1110. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1111. (i==arlFrom.Count-1?"/ ":".");
  1112. }
  1113. break;
  1114. default:
  1115. break;
  1116. }
  1117. break;
  1118. case IPNotation.IPv6BinaryCIDR:
  1119. switch(arg_newValue)
  1120. {
  1121. case IPNotation.IPv4Decimal:
  1122. //do not use the last Item, its the Subnetmask
  1123. //do not use the 1st 4 elements
  1124. for(int i=4; i<arlFrom.Count-1; i++)
  1125. {
  1126. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1127. //Add Dot if its not the last IPPart, else add nothing
  1128. (i==arlFrom.Count-2?"":".");
  1129. }
  1130. break;
  1131. case IPNotation.IPv4DecimalCIDR:
  1132. //do not use the last Item, its the Subnetmask
  1133. for(int i=4; i<arlFrom.Count-1; i++)
  1134. {
  1135. //Convert Binary to Decimal
  1136. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1137. //Add Dot if its not the last IPPart, else add nothing
  1138. (i==arlFrom.Count-2?"":".");
  1139. }
  1140. //Add Subnetmask
  1141. sTo += "/" + arlFrom[arlFrom.Count-1];
  1142. break;
  1143. case IPNotation.IPv4Binary:
  1144. //do not use the last Item, its the Subnetmask
  1145. for(int i=4; i<arlFrom.Count-1; i++)
  1146. {
  1147. //convert from IPv6 Binary to IPv4 Binary
  1148. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1149. //Add Dot if its not the last IPPart, else add nothing
  1150. (i==arlFrom.Count-2?"":".");
  1151. }
  1152. break;
  1153. case IPNotation.IPv4BinaryCIDR:
  1154. //do not use the last Item, its the Subnetmask
  1155. for(int i=4; i<arlFrom.Count-1; i++)
  1156. {
  1157. //convert from IPv6 Binary to IPv4 Binary
  1158. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1159. //Add Dot if its not the last IPPart, else add nothing
  1160. (i==arlFrom.Count-2?"":".");
  1161. }
  1162. //Add Subnetmask
  1163. sTo += "/" + arlFrom[arlFrom.Count-1];
  1164. break;
  1165. case IPNotation.IPv6Hexadecimal:
  1166. for(int i=0; i<arlFrom.Count-1; i++)
  1167. {
  1168. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1169. }
  1170. break;
  1171. case IPNotation.IPv6HexadecimalCIDR:
  1172. for(int i=0; i<arlFrom.Count-1; i++)
  1173. {
  1174. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1175. }
  1176. sTo += "/" + arlFrom[arlFrom.Count-1];
  1177. break;
  1178. case IPNotation.IPv6Binary:
  1179. for(int i=0; i<arlFrom.Count-1; i++)
  1180. {
  1181. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  1182. }
  1183. break;
  1184. case IPNotation.IPv6BinaryCIDR:
  1185. break;
  1186. case IPNotation.IPv6IPv4Decimal:
  1187. sTo = "::";
  1188. for(int i=4; i<arlFrom.Count-1; i++)
  1189. {
  1190. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1191. }
  1192. break;
  1193. case IPNotation.IPv6IPv4DecimalCIDR:
  1194. sTo = "::";
  1195. for(int i=4; i<arlFrom.Count-1; i++)
  1196. {
  1197. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1198. }
  1199. sTo += "/" + arlFrom[arlFrom.Count-1];
  1200. break;
  1201. case IPNotation.IPv6IPv4Binary:
  1202. sTo = "::";
  1203. for(int i=4; i<arlFrom.Count-1; i++)
  1204. {
  1205. //convert from IPv6 Binary to IPv4 Binary
  1206. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1207. (i==arlFrom.Count-2?"":".");
  1208. }
  1209. break;
  1210. case IPNotation.IPv6IPv4BinaryCIDR:
  1211. sTo = "::";
  1212. for(int i=4; i<arlFrom.Count-1; i++)
  1213. {
  1214. //convert from IPv6 Binary to IPv4 Binary
  1215. sTo += this.Dec2Bin(this.Bin2Dec(arlFrom[i].ToString())) +
  1216. (i==arlFrom.Count-2?"":".");
  1217. }
  1218. sTo += "/" + arlFrom[arlFrom.Count-1];
  1219. break;
  1220. default:
  1221. break;
  1222. }
  1223. break;
  1224. case IPNotation.IPv6IPv4Decimal:
  1225. switch(arg_newValue)
  1226. {
  1227. case IPNotation.IPv4Decimal:
  1228. //do not use the 1st 2 elements (::)
  1229. for(int i=2; i<arlFrom.Count; i++)
  1230. {
  1231. sTo += arlFrom[i].ToString() +
  1232. //Add Dot if its not the last IPPart, else add nothing
  1233. (i==arlFrom.Count-1?"":".");
  1234. }
  1235. break;
  1236. case IPNotation.IPv4DecimalCIDR:
  1237. //do not use the 1st 2 elements (::)
  1238. for(int i=2; i<arlFrom.Count; i++)
  1239. {
  1240. sTo += arlFrom[i].ToString() +
  1241. //Add Slash if its the last IPPart, els add a dot
  1242. (i==arlFrom.Count-1?"/ ":".");
  1243. }
  1244. break;
  1245. case IPNotation.IPv4Binary:
  1246. for(int i=2; i<arlFrom.Count; i++)
  1247. {
  1248. //Convert Decimal to Binary
  1249. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  1250. //Add Dot if its not the last IPPart, else add nothing
  1251. (i==arlFrom.Count-1?"":".");
  1252. }
  1253. break;
  1254. case IPNotation.IPv4BinaryCIDR:
  1255. for(int i=2; i<arlFrom.Count; i++)
  1256. {
  1257. //Convert Decimal to Binary
  1258. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  1259. //Add Slash if its the last IPPart, else add a dot
  1260. (i==arlFrom.Count-1?"/ ":".");
  1261. }
  1262. break;
  1263. case IPNotation.IPv6Hexadecimal:
  1264. sTo = "0000:0000:0000:0000:";
  1265. for(int i=2; i<arlFrom.Count; i++)
  1266. {
  1267. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  1268. }
  1269. break;
  1270. case IPNotation.IPv6HexadecimalCIDR:
  1271. sTo = "0000:0000:0000:0000:";
  1272. for(int i=2; i<arlFrom.Count; i++)
  1273. {
  1274. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  1275. }
  1276. break;
  1277. case IPNotation.IPv6Binary:
  1278. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1279. for(int i=2; i<arlFrom.Count; i++)
  1280. {
  1281. sTo += this.Dec2Bin(arlFrom[i].ToString(), true) + (i==arlFrom.Count-1?"":":");
  1282. }
  1283. break;
  1284. case IPNotation.IPv6BinaryCIDR:
  1285. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1286. for(int i=2; i<arlFrom.Count; i++)
  1287. {
  1288. sTo += this.Dec2Bin(arlFrom[i].ToString(), true) + (i==arlFrom.Count-1?"/ ":":");
  1289. }
  1290. break;
  1291. case IPNotation.IPv6IPv4Decimal:
  1292. break;
  1293. case IPNotation.IPv6IPv4DecimalCIDR:
  1294. sTo = "::";
  1295. for(int i=2; i<arlFrom.Count; i++)
  1296. {
  1297. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":".");
  1298. }
  1299. break;
  1300. case IPNotation.IPv6IPv4Binary:
  1301. sTo = "::";
  1302. for(int i=2; i<arlFrom.Count; i++)
  1303. {
  1304. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  1305. }
  1306. break;
  1307. case IPNotation.IPv6IPv4BinaryCIDR:
  1308. sTo = "::";
  1309. for(int i=2; i<arlFrom.Count; i++)
  1310. {
  1311. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  1312. }
  1313. break;
  1314. default:
  1315. break;
  1316. }
  1317. break;
  1318. case IPNotation.IPv6IPv4DecimalCIDR:
  1319. switch(arg_newValue)
  1320. {
  1321. case IPNotation.IPv4Decimal:
  1322. //do not use the last Item, its the Subnetmask
  1323. //do not use th2 1st 2 elements
  1324. for(int i=2; i<arlFrom.Count-1; i++)
  1325. {
  1326. sTo += arlFrom[i].ToString() +
  1327. //Add Dot if its not the last IPPart, else add nothing
  1328. (i==arlFrom.Count-2?"":".");
  1329. }
  1330. break;
  1331. case IPNotation.IPv4DecimalCIDR:
  1332. //do not use the last Item, its the Subnetmask
  1333. //do not use the 1st 2 Elements
  1334. for(int i=2; i<arlFrom.Count-1; i++)
  1335. {
  1336. //Convert Decimal to Binary
  1337. sTo += arlFrom[i].ToString() +
  1338. //Add Dot if its not the last IPPart, else add nothing
  1339. (i==arlFrom.Count-2?"":".");
  1340. }
  1341. //Add Subnetmask
  1342. sTo += "/" + arlFrom[arlFrom.Count-1];
  1343. break;
  1344. case IPNotation.IPv4Binary:
  1345. //do not use the last Item, its the Subnetmask
  1346. for(int i=2; i<arlFrom.Count-1; i++)
  1347. {
  1348. //Convert Decimal to Binary
  1349. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  1350. //Add Dot if its not the last IPPart, else add nothing
  1351. (i==arlFrom.Count-2?"":".");
  1352. }
  1353. break;
  1354. case IPNotation.IPv4BinaryCIDR:
  1355. //do not use the last Item, its the Subnetmask
  1356. for(int i=2; i<arlFrom.Count-1; i++)
  1357. {
  1358. //Convert Decimal to Binary
  1359. sTo += this.Dec2Bin(arlFrom[i].ToString()) +
  1360. //Add Dot if its not the last IPPart, else add nothing
  1361. (i==arlFrom.Count-2?"":".");
  1362. }
  1363. //Add Subnetmask
  1364. sTo += "/" + arlFrom[arlFrom.Count-1];
  1365. break;
  1366. case IPNotation.IPv6Hexadecimal:
  1367. sTo = "0000:0000:0000:0000:";
  1368. for(int i=2; i<arlFrom.Count-1; i++)
  1369. {
  1370. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1371. }
  1372. break;
  1373. case IPNotation.IPv6HexadecimalCIDR:
  1374. sTo = "0000:0000:0000:0000:";
  1375. for(int i=2; i<arlFrom.Count-1; i++)
  1376. {
  1377. sTo += this.Dec2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1378. }
  1379. sTo += "/" + arlFrom[arlFrom.Count-1];
  1380. break;
  1381. case IPNotation.IPv6Binary:
  1382. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1383. for(int i=2; i<arlFrom.Count-1; i++)
  1384. {
  1385. sTo += this.Dec2Bin(arlFrom[i].ToString(),true) + (i==arlFrom.Count-2?"":":");
  1386. }
  1387. break;
  1388. case IPNotation.IPv6BinaryCIDR:
  1389. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1390. for(int i=2; i<arlFrom.Count-1; i++)
  1391. {
  1392. sTo += this.Dec2Bin(arlFrom[i].ToString(),true) + (i==arlFrom.Count-2?"":":");
  1393. }
  1394. sTo += "/" + arlFrom[arlFrom.Count-1];
  1395. break;
  1396. case IPNotation.IPv6IPv4Decimal:
  1397. sTo = "::";
  1398. for(int i=2; i<arlFrom.Count-1; i++)
  1399. {
  1400. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  1401. }
  1402. break;
  1403. case IPNotation.IPv6IPv4DecimalCIDR:
  1404. break;
  1405. case IPNotation.IPv6IPv4Binary:
  1406. sTo = "::";
  1407. for(int i=2; i<arlFrom.Count-1; i++)
  1408. {
  1409. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1410. }
  1411. break;
  1412. case IPNotation.IPv6IPv4BinaryCIDR:
  1413. sTo = "::";
  1414. for(int i=2; i<arlFrom.Count-1; i++)
  1415. {
  1416. sTo += this.Dec2Bin(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1417. }
  1418. sTo += "/" + arlFrom[arlFrom.Count-1];
  1419. break;
  1420. default:
  1421. break;
  1422. }
  1423. break;
  1424. case IPNotation.IPv6IPv4Binary:
  1425. switch(arg_newValue)
  1426. {
  1427. case IPNotation.IPv4Decimal:
  1428. //do not use the 1st 2 elements (::)
  1429. for(int i=2; i<arlFrom.Count; i++)
  1430. {
  1431. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1432. //Add Dot if its not the last IPPart, else add nothing
  1433. (i==arlFrom.Count-1?"":".");
  1434. }
  1435. break;
  1436. case IPNotation.IPv4DecimalCIDR:
  1437. //do not use the 1st 2 elements (::)
  1438. for(int i=2; i<arlFrom.Count; i++)
  1439. {
  1440. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1441. //Add Slash if its the last IPPart, els add a dot
  1442. (i==arlFrom.Count-1?"/ ":".");
  1443. }
  1444. break;
  1445. case IPNotation.IPv4Binary:
  1446. for(int i=2; i<arlFrom.Count; i++)
  1447. {
  1448. //Convert Decimal to Binary
  1449. sTo += arlFrom[i].ToString() +
  1450. //Add Dot if its not the last IPPart, else add nothing
  1451. (i==arlFrom.Count-1?"":".");
  1452. }
  1453. break;
  1454. case IPNotation.IPv4BinaryCIDR:
  1455. for(int i=2; i<arlFrom.Count; i++)
  1456. {
  1457. //Convert Decimal to Binary
  1458. sTo += arlFrom[i].ToString() +
  1459. //Add Slash if its the last IPPart, else add a dot
  1460. (i==arlFrom.Count-1?"/ ":".");
  1461. }
  1462. break;
  1463. case IPNotation.IPv6Hexadecimal:
  1464. sTo = "0000:0000:0000:0000:";
  1465. for(int i=2; i<arlFrom.Count; i++)
  1466. {
  1467. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":":");
  1468. }
  1469. break;
  1470. case IPNotation.IPv6HexadecimalCIDR:
  1471. sTo = "0000:0000:0000:0000:";
  1472. for(int i=2; i<arlFrom.Count; i++)
  1473. {
  1474. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":":");
  1475. }
  1476. break;
  1477. case IPNotation.IPv6Binary:
  1478. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1479. for(int i=2; i<arlFrom.Count; i++)
  1480. {
  1481. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-1?"":":");
  1482. }
  1483. break;
  1484. case IPNotation.IPv6BinaryCIDR:
  1485. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1486. for(int i=2; i<arlFrom.Count; i++)
  1487. {
  1488. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":":");
  1489. }
  1490. break;
  1491. case IPNotation.IPv6IPv4Decimal:
  1492. sTo = "::";
  1493. for(int i=2; i<arlFrom.Count; i++)
  1494. {
  1495. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"":".");
  1496. }
  1497. break;
  1498. case IPNotation.IPv6IPv4DecimalCIDR:
  1499. sTo = "::";
  1500. for(int i=2; i<arlFrom.Count; i++)
  1501. {
  1502. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-1?"/ ":".");
  1503. }
  1504. break;
  1505. case IPNotation.IPv6IPv4Binary:
  1506. break;
  1507. case IPNotation.IPv6IPv4BinaryCIDR:
  1508. sTo = "::";
  1509. for(int i=2; i<arlFrom.Count; i++)
  1510. {
  1511. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-1?"/ ":".");
  1512. }
  1513. break;
  1514. default:
  1515. break;
  1516. }
  1517. break;
  1518. case IPNotation.IPv6IPv4BinaryCIDR:
  1519. switch(arg_newValue)
  1520. {
  1521. case IPNotation.IPv4Decimal:
  1522. //do not use the last Item, its the Subnetmask
  1523. //do not use th2 1st 2 elements
  1524. for(int i=2; i<arlFrom.Count-1; i++)
  1525. {
  1526. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1527. //Add Dot if its not the last IPPart, else add nothing
  1528. (i==arlFrom.Count-2?"":".");
  1529. }
  1530. break;
  1531. case IPNotation.IPv4DecimalCIDR:
  1532. //do not use the last Item, its the Subnetmask
  1533. //do not use the 1st 2 Elements
  1534. for(int i=2; i<arlFrom.Count-1; i++)
  1535. {
  1536. //Convert Decimal to Binary
  1537. sTo += this.Bin2Dec(arlFrom[i].ToString()) +
  1538. //Add Dot if its not the last IPPart, else add nothing
  1539. (i==arlFrom.Count-2?"":".");
  1540. }
  1541. //Add Subnetmask
  1542. sTo += "/" + arlFrom[arlFrom.Count-1];
  1543. break;
  1544. case IPNotation.IPv4Binary:
  1545. //do not use the last Item, its the Subnetmask
  1546. for(int i=2; i<arlFrom.Count-1; i++)
  1547. {
  1548. //Convert Decimal to Binary
  1549. sTo += arlFrom[i].ToString() +
  1550. //Add Dot if its not the last IPPart, else add nothing
  1551. (i==arlFrom.Count-2?"":".");
  1552. }
  1553. break;
  1554. case IPNotation.IPv4BinaryCIDR:
  1555. //do not use the last Item, its the Subnetmask
  1556. for(int i=2; i<arlFrom.Count-1; i++)
  1557. {
  1558. //Convert Decimal to Binary
  1559. sTo += arlFrom[i].ToString() +
  1560. //Add Dot if its not the last IPPart, else add nothing
  1561. (i==arlFrom.Count-2?"":".");
  1562. }
  1563. //Add Subnetmask
  1564. sTo += "/" + arlFrom[arlFrom.Count-1];
  1565. break;
  1566. case IPNotation.IPv6Hexadecimal:
  1567. sTo = "0000:0000:0000:0000:";
  1568. for(int i=2; i<arlFrom.Count-1; i++)
  1569. {
  1570. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1571. }
  1572. break;
  1573. case IPNotation.IPv6HexadecimalCIDR:
  1574. sTo = "0000:0000:0000:0000:";
  1575. for(int i=2; i<arlFrom.Count-1; i++)
  1576. {
  1577. sTo += this.Bin2Hex(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":":");
  1578. }
  1579. sTo += "/" + arlFrom[arlFrom.Count-1];
  1580. break;
  1581. case IPNotation.IPv6Binary:
  1582. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1583. for(int i=2; i<arlFrom.Count-1; i++)
  1584. {
  1585. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  1586. }
  1587. break;
  1588. case IPNotation.IPv6BinaryCIDR:
  1589. sTo = "0000000000000000:0000000000000000:0000000000000000:0000000000000000:";
  1590. for(int i=2; i<arlFrom.Count-1; i++)
  1591. {
  1592. sTo += "00000000" + arlFrom[i].ToString() + (i==arlFrom.Count-2?"":":");
  1593. }
  1594. sTo += "/" + arlFrom[arlFrom.Count-1];
  1595. break;
  1596. case IPNotation.IPv6IPv4Decimal:
  1597. sTo = "::";
  1598. for(int i=2; i<arlFrom.Count-1; i++)
  1599. {
  1600. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1601. }
  1602. break;
  1603. case IPNotation.IPv6IPv4DecimalCIDR:
  1604. sTo = "::";
  1605. for(int i=2; i<arlFrom.Count-1; i++)
  1606. {
  1607. sTo += this.Bin2Dec(arlFrom[i].ToString()) + (i==arlFrom.Count-2?"":".");
  1608. }
  1609. sTo += "/" + arlFrom[arlFrom.Count-1];
  1610. break;
  1611. case IPNotation.IPv6IPv4Binary:
  1612. sTo = "::";
  1613. for(int i=2; i<arlFrom.Count-1; i++)
  1614. {
  1615. sTo += arlFrom[i].ToString() + (i==arlFrom.Count-2?"":".");
  1616. }
  1617. break;
  1618. case IPNotation.IPv6IPv4BinaryCIDR:
  1619. break;
  1620. default:
  1621. break;
  1622. }
  1623. break;
  1624. default:
  1625. break;
  1626. }
  1627. this.Text = sTo;
  1628. this.MaxLength = this.TextLength;
  1629. }
  1630. /// <summary>
  1631. /// Occures when Behaviour-Mode OverWriteMode was changed
  1632. /// </summary>
  1633. /// <param name="arg_bValue">Value, Overwrite Numbers in Editfield or not</param>
  1634. protected virtual void OnOverWriteChanged(bool arg_bValue)
  1635. {
  1636. if(this.OverWriteModeChanged!=null)
  1637. this.OverWriteModeChanged(arg_bValue);
  1638. }
  1639. /// <summary>
  1640. /// Occures when Behaviour-Mode PreventLeave was changed
  1641. /// </summary>
  1642. /// <param name="arg_bValue">Value, leave control if there is an error or not</param>
  1643. protected virtual void OnPreventLeaveChanged(bool arg_bValue)
  1644. {
  1645. if(this.PreventLeaveChanged!=null)
  1646. this.PreventLeaveChanged(arg_bValue);
  1647. }
  1648. #endregion //events
  1649. #region Event-Overrides
  1650. /// <summary>
  1651. /// Override standard KeyDownEventHandler
  1652. /// Catches Inputs of "." and "/" to jump to next positions
  1653. /// </summary>
  1654. /// <param name="e">KeyEventArgument</param>
  1655. protected override void OnKeyDown(KeyEventArgs e)
  1656. {
  1657. //Zeichen an die richtige stelle schreiben
  1658. int iPos = this.SelectionStart;
  1659. char[] cText = this.Text.ToCharArray();
  1660. if(e.Modifiers == Keys.None)
  1661. {
  1662. if((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> `
  1663. && iPos < this.TextLength)
  1664. {
  1665. if(this.m_arlDelimeter.Contains(cText[iPos]))
  1666. iPos+=1;
  1667. this.SelectionStart = iPos;
  1668. if(this.OverWriteMode)
  1669. {
  1670. if(iPos < this.TextLength)
  1671. this.SelectionLength = 1;
  1672. }
  1673. else
  1674. {
  1675. if(iPos < this.TextLength)
  1676. if(cText[iPos] == ' ')
  1677. this.SelectionLength = 1;
  1678. }
  1679. }
  1680. }
  1681. base.OnKeyDown (e);
  1682. }
  1683. /// <summary>
  1684. /// Override standard KeyUpEventHandler
  1685. /// Catches Inputs of "." and "/" to jump to next positions
  1686. /// </summary>
  1687. /// <param name="e">KeyEventArgument</param>
  1688. protected override void OnKeyUp(KeyEventArgs e)
  1689. {
  1690. //Zeichen an die richtige stelle schreiben
  1691. int iPos = this.SelectionStart;
  1692. char[] cText = this.Text.ToCharArray();
  1693. //Cursor hintern Punkt setzen
  1694. if((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> `
  1695. && iPos < this.TextLength)
  1696. {
  1697. if(this.m_arlDelimeter.Contains(cText[iPos]))
  1698. iPos+=1;
  1699. this.SelectionStart = iPos;
  1700. }
  1701. base.OnKeyUp (e);
  1702. }
  1703. /// <summary>
  1704. /// Override standard KeyPressEventHandler
  1705. /// Catches Inputs of "." and "/" to jump to next positions
  1706. /// </summary>
  1707. /// <param name="e">KeyPressEventArgument</param>
  1708. protected override void OnKeyPress(KeyPressEventArgs e)
  1709. {
  1710. //valid input charachters
  1711. if(char.IsControl(e.KeyChar) ||
  1712. m_regexValidNumbers.IsMatch(e.KeyChar.ToString()))
  1713. {
  1714. e.Handled = false;
  1715. }
  1716. else
  1717. {
  1718. switch(e.KeyChar)
  1719. {
  1720. case '/':
  1721. this.JumpToSlash();
  1722. break;
  1723. case '.':
  1724. case ':':
  1725. this.JumpToNextDot();
  1726. break;
  1727. default:
  1728. break;
  1729. }
  1730. e.Handled = true;
  1731. }
  1732. base.OnKeyPress(e);
  1733. }
  1734. /// <summary>
  1735. /// Override standard TextChangedEventHandler
  1736. /// Looks if inserted IP-Address is valid
  1737. /// </summary>
  1738. /// <param name="e">EventArgument</param>
  1739. protected override void OnTextChanged(EventArgs e)
  1740. {
  1741. base.OnTextChanged (e);
  1742. if(this.Text.Length == 0)
  1743. this.ResetText();
  1744. try
  1745. {
  1746. if(!this.ValidateIP())
  1747. this.error.SetError(this,"Invalid IP-address");
  1748. else
  1749. this.error.SetError(this,"");
  1750. }
  1751. catch(Exception LastError)
  1752. {
  1753. this.error.SetError(this,LastError.Message);
  1754. }
  1755. }
  1756. /// <summary>
  1757. /// Override standard ValidatingEventHandler
  1758. /// Validates inserted IP-Address, and cancels Textbox if valid or PreventLeave=false
  1759. /// </summary>
  1760. /// <param name="e">CancelEventArgument</param>
  1761. protected override void OnValidating(CancelEventArgs e)
  1762. {
  1763. //e.Cancel = true;//suppress cancel-signal = not validated
  1764. e.Cancel = (!this.ValidateIP() && this.m_bPreventLeave);
  1765. base.OnValidating (e);
  1766. }
  1767. #endregion //Eventhandling
  1768. #region Methods
  1769. /// <summary>
  1770. /// Override standard ResetText
  1771. /// Fills Textbox with Dots and Slashes dependend on Properties
  1772. /// </summary>
  1773. public override void ResetText()
  1774. {
  1775. base.ResetText();
  1776. switch(this.Notation)
  1777. {
  1778. case IPNotation.IPv4Decimal:
  1779. this.Text = " . . . ";
  1780. break;
  1781. case IPNotation.IPv4DecimalCIDR:
  1782. this.Text = " . . . / ";
  1783. break;
  1784. case IPNotation.IPv4Binary:
  1785. this.Text = " . . . ";
  1786. break;
  1787. case IPNotation.IPv4BinaryCIDR:
  1788. this.Text = " . . . / ";
  1789. break;
  1790. case IPNotation.IPv6Hexadecimal:
  1791. this.Text = " : : : : : : ";
  1792. break;
  1793. case IPNotation.IPv6HexadecimalCIDR:
  1794. this.Text = " : : : : : : / ";
  1795. break;
  1796. case IPNotation.IPv6Binary:
  1797. this.Text = " : : : : : : ";
  1798. break;
  1799. case IPNotation.IPv6BinaryCIDR:
  1800. this.Text = " : : : : : : / ";
  1801. break;
  1802. case IPNotation.IPv6IPv4Decimal:
  1803. this.Text = ":: . . . ";
  1804. break;
  1805. case IPNotation.IPv6IPv4DecimalCIDR:
  1806. this.Text = ":: . . . / ";
  1807. break;
  1808. case IPNotation.IPv6IPv4Binary:
  1809. this.Text = ":: . . . ";
  1810. break;
  1811. case IPNotation.IPv6IPv4BinaryCIDR:
  1812. this.Text = ":: . . . / ";
  1813. break;
  1814. default:
  1815. break;
  1816. }
  1817. this.MaxLength = this.TextLength;
  1818. }
  1819. /// <summary>
  1820. /// Window-Message Constant
  1821. /// </summary>
  1822. protected const int WM_KEYDOWN = 0x0100;
  1823. /// <summary>
  1824. /// Override standard PreProcessMessge
  1825. /// Catches Inputs of Backspaces and Deletes to remove IP-Digits at the right position
  1826. /// </summary>
  1827. /// <param name="msg">Process Message</param>
  1828. public override bool PreProcessMessage(ref Message msg)
  1829. {
  1830. if (msg.Msg == WM_KEYDOWN)
  1831. {
  1832. Keys keyData = ((Keys) (int) msg.WParam) | ModifierKeys;
  1833. Keys keyCode = ((Keys) (int) msg.WParam);
  1834. int iPos = this.SelectionStart;
  1835. char[] cText = this.Text.ToCharArray();
  1836. switch(keyCode)
  1837. {
  1838. case Keys.Delete:
  1839. if(iPos < this.TextLength)
  1840. {
  1841. while(cText[iPos] == '.' || cText[iPos] == ':' || cText[iPos] == '/')
  1842. {
  1843. if((iPos+=1) >= cText.Length)
  1844. break;
  1845. }
  1846. if(iPos<this.TextLength)
  1847. {
  1848. base.Text = this.Text.Substring(0,iPos) + " " + this.Text.Substring(iPos+1);
  1849. this.SelectionStart = iPos+1;
  1850. }
  1851. else
  1852. this.SelectionStart = this.TextLength-1;
  1853. }
  1854. return true;
  1855. case Keys.Back:
  1856. if(iPos > 0)
  1857. {
  1858. while(cText[iPos-1] == '.' || cText[iPos-1] == ':' || cText[iPos-1] == '/')
  1859. {
  1860. if((iPos-=1)<=0)
  1861. break;
  1862. }
  1863. if(iPos>0)
  1864. {
  1865. base.Text = this.Text.Substring(0,iPos-1) + " " + this.Text.Substring(iPos);
  1866. this.SelectionStart = iPos-1;
  1867. }
  1868. else
  1869. this.SelectionStart = 0;
  1870. }
  1871. return true;
  1872. default:
  1873. break;
  1874. }
  1875. }
  1876. return base.PreProcessMessage (ref msg);
  1877. }
  1878. /// <summary>
  1879. /// Returns the formatted IP-Addresses without spaces and Zeroes
  1880. /// </summary>
  1881. /// <returns>IP-Address without spaces and Zeroes</returns>
  1882. public string GetPureIPAddress()
  1883. {
  1884. string s = "";
  1885. ArrayList arlIP = new ArrayList(this.Text.Replace(" ","").Split((char[])this.m_arlDelimeter.ToArray(typeof(char))));
  1886. for(int i=0; i<arlIP.Count; i++)
  1887. {
  1888. while(arlIP[i].ToString().StartsWith("0"))
  1889. arlIP[i] = arlIP[i].ToString().Substring(1);
  1890. }
  1891. s = IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), this.m_ipNotation);
  1892. //in IPv6 Addresses replace 0000: by ::
  1893. if(this.m_ipNotation == IPNotation.IPv6Hexadecimal ||
  1894. this.m_ipNotation == IPNotation.IPv6HexadecimalCIDR ||
  1895. this.m_ipNotation == IPNotation.IPv6Binary ||
  1896. this.m_ipNotation == IPNotation.IPv6BinaryCIDR)
  1897. {
  1898. while(s.IndexOf(":::")>=0)
  1899. {
  1900. s = s.Remove(s.IndexOf(":::"),1);
  1901. }
  1902. }
  1903. return s;
  1904. }
  1905. #endregion //Methods
  1906. #region Helperfunctions
  1907. /// <summary>
  1908. /// Sets Inputcursor to Subnet-Slash
  1909. /// </summary>
  1910. private void JumpToSlash()
  1911. {
  1912. int iSelStart = this.Text.LastIndexOf("/");
  1913. if(iSelStart >= 0)
  1914. {
  1915. this.Select(iSelStart+1,0);
  1916. }
  1917. }
  1918. /// <summary>
  1919. /// Sets input cursour to next Dot
  1920. /// </summary>
  1921. private void JumpToNextDot()
  1922. {
  1923. int iSelStart = this.Text.IndexOf('.',this.SelectionStart);
  1924. if(iSelStart >= 0)
  1925. {
  1926. this.Select(iSelStart+1,0);
  1927. }
  1928. else
  1929. {
  1930. iSelStart = this.Text.IndexOf(':',this.SelectionStart);
  1931. if(iSelStart >= 0)
  1932. {
  1933. this.Select(iSelStart+1,0);
  1934. }
  1935. }
  1936. }
  1937. /// <summary>
  1938. /// Converts Decimal IP-Part to Binary (default IPv6 = false)
  1939. /// </summary>
  1940. /// <param name="arg_sDec">Decimal IP-Part</param>
  1941. /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param>
  1942. /// <returns>Binary IP-Part</returns>
  1943. private string Dec2Bin(string arg_sDec)
  1944. {
  1945. return this.Dec2Bin(arg_sDec, false);
  1946. }
  1947. /// <summary>
  1948. /// Converts Decimal IP-Part to Binary
  1949. /// </summary>
  1950. /// <param name="arg_sDec">Decimal IP-Part</param>
  1951. /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param>
  1952. /// <returns>Binary IP-Part</returns>
  1953. private string Dec2Bin(string arg_sDec, bool arg_bIPv6)
  1954. {
  1955. string sBin = (arg_bIPv6?"0000000000000000":"00000000"), sSubnet = "";
  1956. arg_sDec = arg_sDec.Trim();
  1957. while(arg_sDec.Length<3)
  1958. arg_sDec = "0" + arg_sDec;
  1959. if(arg_sDec.IndexOf("/")>=0)
  1960. {
  1961. sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/"));
  1962. arg_sDec = arg_sDec.Substring(0,arg_sDec.IndexOf("/"));
  1963. }
  1964. int iDec = Convert.ToInt32(arg_sDec, 10);
  1965. sBin = Convert.ToString(iDec, 2);
  1966. while(sBin.Length<(arg_bIPv6?16:8))
  1967. sBin = "0" + sBin;
  1968. return sBin + sSubnet;
  1969. }
  1970. /// <summary>
  1971. /// Converts Binary IP-Part to Decimal
  1972. /// </summary>
  1973. /// <param name="arg_sBin">Binary IP-Part</param>
  1974. /// <returns>Decimal IP-Part</returns>
  1975. private string Bin2Dec(string arg_sBin)
  1976. {
  1977. string sDec = "000", sSubnet = "";
  1978. arg_sBin = arg_sBin.Trim();
  1979. while(arg_sBin.Length<8)
  1980. arg_sBin = "0" + arg_sBin;
  1981. if(arg_sBin.IndexOf("/")>=0)
  1982. {
  1983. sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/"));
  1984. arg_sBin = arg_sBin.Substring(0,arg_sBin.IndexOf("/"));
  1985. }
  1986. int iBin = Convert.ToInt32(arg_sBin, 2);
  1987. if(iBin>255)
  1988. throw new Exception(string.Format("Can't convert Binary to Decimal IP-Address\nbin:{0} is greater than 255",iBin));
  1989. sDec = Convert.ToString(iBin, 10);
  1990. while(sDec.Length<3)
  1991. sDec = "0" + sDec;
  1992. return sDec + sSubnet;
  1993. }
  1994. /// <summary>
  1995. /// Converts Binary IP-Part to Hexadecimal
  1996. /// </summary>
  1997. /// <param name="arg_sBin">Binary IP-Part</param>
  1998. /// <returns>Hexadecimal IP-Part</returns>
  1999. private string Bin2Hex(string arg_sBin)
  2000. {
  2001. string sHex = "0000", sSubnet = "";
  2002. arg_sBin = arg_sBin.Trim();
  2003. while(arg_sBin.Length<8)
  2004. arg_sBin = "0" + arg_sBin;
  2005. if(arg_sBin.IndexOf("/")>=0)
  2006. {
  2007. sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/"));
  2008. arg_sBin = arg_sBin.Substring(0,arg_sBin.IndexOf("/"));
  2009. }
  2010. int iBin = Convert.ToInt32(arg_sBin, 2);
  2011. sHex = Convert.ToString(iBin, 16);
  2012. while(sHex.Length<4)
  2013. sHex = "0" + sHex;
  2014. return sHex + sSubnet;
  2015. }
  2016. /// <summary>
  2017. /// Converts Hexadecimal IP-Part to Binary (default IPv6=true)
  2018. /// </summary>
  2019. /// <param name="arg_sHex">Hexadecimal IP-Part</param>
  2020. /// <returns>Binary IP-Part</returns>
  2021. private string Hex2Bin(string arg_sHex)
  2022. {
  2023. return this.Hex2Bin(arg_sHex, true);
  2024. }
  2025. /// <summary>
  2026. /// Converts Hexadecimal IP-Part to Binary
  2027. /// </summary>
  2028. /// <param name="arg_sHex">Hexadecimal IP-Part</param>
  2029. /// <param name="arg_bIPv6">Binary for IPv6 (16 digits)</param>
  2030. /// <returns>Binary IP-Part</returns>
  2031. private string Hex2Bin(string arg_sHex, bool arg_bIPv6)
  2032. {
  2033. string sBin = (arg_bIPv6?"0000000000000000":"00000000"), sSubnet = "";
  2034. arg_sHex = arg_sHex.Trim();
  2035. while(arg_sHex.Length<3)
  2036. arg_sHex = "0" + arg_sHex;
  2037. if(arg_sHex.IndexOf("/")>=0)
  2038. {
  2039. sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/"));
  2040. arg_sHex = arg_sHex.Substring(0,arg_sHex.IndexOf("/"));
  2041. }
  2042. int iHex = Convert.ToInt32(arg_sHex, 16);
  2043. if(iHex>255 && !arg_bIPv6)
  2044. throw new Exception(string.Format("Can't convert Hexadecimal to Binary IP-Address\nhex:{0} is greater than 11111111",iHex));
  2045. sBin = Convert.ToString(iHex, 2);
  2046. while(sBin.Length<(arg_bIPv6?16:8))
  2047. sBin = "0" + sBin;
  2048. return sBin + sSubnet;
  2049. }
  2050. /// <summary>
  2051. /// Converts Decimal IP-Part to Hexadecimal
  2052. /// </summary>
  2053. /// <param name="arg_sDec">Decimal IP-Part</param>
  2054. /// <returns>Hexadecimal IP-Part</returns>
  2055. private string Dec2Hex(string arg_sDec)
  2056. {
  2057. string sHex = "0000", sSubnet = "";
  2058. arg_sDec = arg_sDec.Trim();
  2059. while(arg_sDec.Length<8)
  2060. arg_sDec = "0" + arg_sDec;
  2061. if(arg_sDec.IndexOf("/")>=0)
  2062. {
  2063. sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/"));
  2064. arg_sDec = arg_sDec.Substring(0,arg_sDec.IndexOf("/"));
  2065. }
  2066. int iDec = Convert.ToInt32(arg_sDec, 10);
  2067. sHex = Convert.ToString(iDec, 16);
  2068. while(sHex.Length<4)
  2069. sHex = "0" + sHex;
  2070. return sHex + sSubnet;
  2071. }
  2072. /// <summary>
  2073. /// Converts Hexadecimal IP-Part to Decimal
  2074. /// </summary>
  2075. /// <param name="arg_sHex">Hexadecimal IP-Part</param>
  2076. /// <returns>Decimal IP-Part</returns>
  2077. private string Hex2Dec(string arg_sHex)
  2078. {
  2079. string sDec = "000", sSubnet = "";
  2080. arg_sHex = arg_sHex.Trim();
  2081. while(arg_sHex.Length<8)
  2082. arg_sHex = "0" + arg_sHex;
  2083. if(arg_sHex.IndexOf("/")>=0)
  2084. {
  2085. sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/"));
  2086. arg_sHex = arg_sHex.Substring(0,arg_sHex.IndexOf("/"));
  2087. }
  2088. int iHex = Convert.ToInt32(arg_sHex, 16);
  2089. if(iHex>255)
  2090. throw new Exception(string.Format("Can't convert Hexadecimal to Decimal IP-Address\nhex:{0} is greater than 255",iHex));
  2091. sDec = Convert.ToString(iHex, 10);
  2092. while(sDec.Length<3)
  2093. sDec = "0" + sDec;
  2094. return sDec + sSubnet;
  2095. }
  2096. /// <summary>
  2097. /// Checks if IP in Textfield is valid
  2098. /// </summary>
  2099. /// <returns>true/false valid/not</returns>
  2100. private bool ValidateIP()
  2101. {
  2102. if(IPAddressTextBox.ValidateIP(this.Text, this.m_newIPNotation, this.m_arlDelimeter))
  2103. return true;
  2104. else
  2105. //if Control is not visible or enabled, it doesn't matter if IP is valid
  2106. return this.Enabled||this.Visible?false:true;
  2107. }
  2108. /// <summary>
  2109. /// Checks if the given String is an valid ip-address
  2110. /// </summary>
  2111. /// <param name="arg_sIP">IP-String</param>
  2112. /// <param name="arg_ipNotation">IP-notation</param>
  2113. /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>
  2114. /// <returns>true/false validated/not</returns>
  2115. protected static bool ValidateIP(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter)
  2116. {
  2117. bool bValidated = false;
  2118. ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));
  2119. try
  2120. {
  2121. switch(arg_ipNotation)
  2122. {
  2123. case IPNotation.IPv4Decimal:
  2124. case IPNotation.IPv4Binary:
  2125. bValidated = arlIP.Count == 4;
  2126. break;
  2127. case IPNotation.IPv4DecimalCIDR:
  2128. case IPNotation.IPv4BinaryCIDR:
  2129. bValidated = arlIP.Count == 5;
  2130. break;
  2131. case IPNotation.IPv6Hexadecimal:
  2132. case IPNotation.IPv6Binary:
  2133. bValidated = arlIP.Count == 8;
  2134. break;
  2135. case IPNotation.IPv6HexadecimalCIDR:
  2136. case IPNotation.IPv6BinaryCIDR:
  2137. bValidated = arlIP.Count == 9;
  2138. break;
  2139. case IPNotation.IPv6IPv4Decimal:
  2140. case IPNotation.IPv6IPv4Binary:
  2141. bValidated = arlIP.Count == 6;
  2142. break;
  2143. case IPNotation.IPv6IPv4DecimalCIDR:
  2144. case IPNotation.IPv6IPv4BinaryCIDR:
  2145. bValidated = arlIP.Count == 7;
  2146. break;
  2147. default:
  2148. break;
  2149. }
  2150. if(!bValidated)
  2151. {
  2152. throw new Exception("IP-Address has wrong element count");
  2153. }
  2154. //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation
  2155. for(int i=(arg_ipNotation.ToString().IndexOf("IPv6IPv4")==0?2:0);
  2156. //don't check the subnet element
  2157. i<(arg_ipNotation.ToString().IndexOf("CIDR")>0?arlIP.Count-1:arlIP.Count);
  2158. i++)
  2159. {
  2160. string sIPPart = arlIP[i].ToString().Replace(" ","");
  2161. int iIPPart = 0;
  2162. switch(arg_ipNotation)
  2163. {
  2164. case IPNotation.IPv4Decimal:
  2165. case IPNotation.IPv4DecimalCIDR:
  2166. case IPNotation.IPv6IPv4Decimal:
  2167. case IPNotation.IPv6IPv4DecimalCIDR:
  2168. while(sIPPart.Length<3)
  2169. sIPPart = "0" + sIPPart;
  2170. iIPPart = Convert.ToInt32(sIPPart, 10);
  2171. if(iIPPart<256)
  2172. bValidated = true;
  2173. else
  2174. bValidated = false;
  2175. break;
  2176. case IPNotation.IPv4Binary:
  2177. case IPNotation.IPv4BinaryCIDR:
  2178. case IPNotation.IPv6IPv4Binary:
  2179. case IPNotation.IPv6IPv4BinaryCIDR:
  2180. while(sIPPart.Length<8)
  2181. sIPPart = "0" + sIPPart;
  2182. iIPPart = Convert.ToInt32(sIPPart, 2);
  2183. if(iIPPart<256)
  2184. bValidated = true;
  2185. else
  2186. bValidated = false;
  2187. break;
  2188. case IPNotation.IPv6Hexadecimal:
  2189. case IPNotation.IPv6HexadecimalCIDR:
  2190. while(sIPPart.Length<4)
  2191. sIPPart = "0" + sIPPart;
  2192. iIPPart = Convert.ToInt32(sIPPart, 16);
  2193. if(iIPPart<65536)
  2194. bValidated = true;
  2195. else
  2196. bValidated = false;
  2197. break;
  2198. case IPNotation.IPv6Binary:
  2199. case IPNotation.IPv6BinaryCIDR:
  2200. while(sIPPart.Length<16)
  2201. sIPPart = "0" + sIPPart;
  2202. iIPPart = Convert.ToInt32(sIPPart, 2);
  2203. if(iIPPart<65536)
  2204. bValidated = true;
  2205. else
  2206. bValidated = false;
  2207. break;
  2208. default:
  2209. break;
  2210. }
  2211. if(!bValidated)
  2212. {
  2213. throw new Exception(string.Format("IP-Address element {0}({1}) has wrong format", i, sIPPart));
  2214. }
  2215. }
  2216. }
  2217. catch(Exception LastError)
  2218. {
  2219. System.Diagnostics.Debug.WriteLine(LastError.Message);
  2220. bValidated = false;
  2221. throw LastError;
  2222. }
  2223. return bValidated;
  2224. }
  2225. /// <summary>
  2226. /// Adds Spaces to given IP-Address, so it fits in the textfield
  2227. /// </summary>
  2228. /// <param name="arg_sIP">IP-String</param>
  2229. /// <param name="arg_ipNotation">IP-notation</param>
  2230. /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>
  2231. /// <returns>IP-Address with Spaces</returns>
  2232. protected static string MakeValidSpaces(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter)
  2233. {
  2234. ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));
  2235. //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation
  2236. for(int i=(arg_ipNotation.ToString().IndexOf("IPv6IPv4")==0?2:0);
  2237. //don't check the subnet element
  2238. i<(arg_ipNotation.ToString().IndexOf("CIDR")>0?arlIP.Count-1:arlIP.Count);
  2239. i++)
  2240. {
  2241. switch(arg_ipNotation)
  2242. {
  2243. case IPNotation.IPv4Decimal:
  2244. case IPNotation.IPv4DecimalCIDR:
  2245. case IPNotation.IPv6IPv4Decimal:
  2246. case IPNotation.IPv6IPv4DecimalCIDR:
  2247. while(arlIP[i].ToString().Length<3)
  2248. arlIP[i] = arlIP[i].ToString() + " ";
  2249. break;
  2250. case IPNotation.IPv4Binary:
  2251. case IPNotation.IPv4BinaryCIDR:
  2252. case IPNotation.IPv6IPv4Binary:
  2253. case IPNotation.IPv6IPv4BinaryCIDR:
  2254. while(arlIP[i].ToString().Length<8)
  2255. arlIP[i] = arlIP[i].ToString() + " ";
  2256. break;
  2257. case IPNotation.IPv6Hexadecimal:
  2258. case IPNotation.IPv6HexadecimalCIDR:
  2259. while(arlIP[i].ToString().Length<4)
  2260. arlIP[i] = arlIP[i].ToString() + " ";
  2261. break;
  2262. case IPNotation.IPv6Binary:
  2263. case IPNotation.IPv6BinaryCIDR:
  2264. while(arlIP[i].ToString().Length<16)
  2265. arlIP[i] = arlIP[i].ToString() + " ";
  2266. break;
  2267. default:
  2268. break;
  2269. }
  2270. }
  2271. return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation);
  2272. }
  2273. /// <summary>
  2274. /// Adds Zeroes to given IP-Address, so it fits in the textfield
  2275. /// </summary>
  2276. /// <param name="arg_sIP">IP-String</param>
  2277. /// <param name="arg_ipNotation">IP-notation</param>
  2278. /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>
  2279. /// <returns>IP-Address with Spaces</returns>
  2280. protected static string MakeValidZeroes(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter)
  2281. {
  2282. ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));
  2283. //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation
  2284. for(int i=(arg_ipNotation.ToString().IndexOf("IPv6IPv4")==0?2:0);
  2285. //don't check the subnet element
  2286. i<(arg_ipNotation.ToString().IndexOf("CIDR")>0?arlIP.Count-1:arlIP.Count);
  2287. i++)
  2288. {
  2289. switch(arg_ipNotation)
  2290. {
  2291. case IPNotation.IPv4Decimal:
  2292. case IPNotation.IPv4DecimalCIDR:
  2293. case IPNotation.IPv6IPv4Decimal:
  2294. case IPNotation.IPv6IPv4DecimalCIDR:
  2295. while(arlIP[i].ToString().Length<3)
  2296. arlIP[i] = "0" + arlIP[i].ToString();
  2297. break;
  2298. case IPNotation.IPv4Binary:
  2299. case IPNotation.IPv4BinaryCIDR:
  2300. case IPNotation.IPv6IPv4Binary:
  2301. case IPNotation.IPv6IPv4BinaryCIDR:
  2302. while(arlIP[i].ToString().Length<8)
  2303. arlIP[i] = "0" + arlIP[i].ToString();
  2304. break;
  2305. case IPNotation.IPv6Hexadecimal:
  2306. case IPNotation.IPv6HexadecimalCIDR:
  2307. while(arlIP[i].ToString().Length<4)
  2308. arlIP[i] = "0" + arlIP[i].ToString();
  2309. break;
  2310. case IPNotation.IPv6Binary:
  2311. case IPNotation.IPv6BinaryCIDR:
  2312. while(arlIP[i].ToString().Length<16)
  2313. arlIP[i] = "0" + arlIP[i].ToString();
  2314. break;
  2315. default:
  2316. break;
  2317. }
  2318. }
  2319. return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation);
  2320. }
  2321. /// <summary>
  2322. /// Creates IP-Addresstring from given StrignArray and Notation
  2323. /// </summary>
  2324. /// <param name="arg_sIP">String-Array with elements for IP-Address</param>
  2325. /// <param name="arg_ipNotation">Notation of IP-Address</param>
  2326. /// <returns>IPAddress-String</returns>
  2327. protected static string MakeIP(string[] arg_sIP, IPNotation arg_ipNotation)
  2328. {
  2329. string s="";
  2330. for(int i=0; i<arg_sIP.Length; i++)
  2331. {
  2332. switch(arg_ipNotation)
  2333. {
  2334. case IPNotation.IPv4Decimal:
  2335. case IPNotation.IPv4Binary:
  2336. s += (arg_sIP[i].Length>0?arg_sIP[i]:"0") + (i<(arg_sIP.Length-1)?".":"");
  2337. break;
  2338. case IPNotation.IPv4DecimalCIDR:
  2339. case IPNotation.IPv4BinaryCIDR:
  2340. s += (arg_sIP[i].Length>0?arg_sIP[i]:"0") + (i<(arg_sIP.Length-2)?".":(i<arg_sIP.Length-1)?"/":"");
  2341. break;
  2342. case IPNotation.IPv6Hexadecimal:
  2343. case IPNotation.IPv6Binary:
  2344. s += arg_sIP[i] + (i<(arg_sIP.Length-1)?":":"");
  2345. break;
  2346. case IPNotation.IPv6HexadecimalCIDR:
  2347. case IPNotation.IPv6BinaryCIDR:
  2348. s += arg_sIP[i] + (i<(arg_sIP.Length-2)?":":(i<arg_sIP.Length-1)?"/":"");
  2349. break;
  2350. case IPNotation.IPv6IPv4Decimal:
  2351. case IPNotation.IPv6IPv4Binary:
  2352. s += (i<2?"":(arg_sIP[i].Length>0?arg_sIP[i]:"0")) + (i<(arg_sIP.Length-1)?(i<2?":":"."):"");
  2353. break;
  2354. case IPNotation.IPv6IPv4DecimalCIDR:
  2355. case IPNotation.IPv6IPv4BinaryCIDR:
  2356. s += (i<2?"":(arg_sIP[i].Length>0?arg_sIP[i]:"0")) + (i<(arg_sIP.Length-2)?(i<2?":":"."):(i<arg_sIP.Length-1)?"/":"");
  2357. break;
  2358. default:
  2359. break;
  2360. }
  2361. }
  2362. return s;
  2363. }
  2364. #endregion //Helperfunctions
  2365. }
  2366. }