From be230dbb81927b2c281f478e4446fd2665ed4b95 Mon Sep 17 00:00:00 2001 From: breelock Date: Wed, 21 Jun 2023 16:57:46 +0300 Subject: [PATCH] first commit --- IpChecker.Console/Compile.bat | 5 + IpChecker.Console/IpChecker.csproj | 10 + IpChecker.Console/Program.cs | 92 ++ IpChecker.Console/Resources/Icon.ico | Bin 0 -> 161862 bytes IpChecker.Console/SimpleJSON.cs | 1317 ++++++++++++++++++++++++++ IpChecker.GUI/Compile.bat | 5 + IpChecker.GUI/Form1.Designer.cs | 335 +++++++ IpChecker.GUI/Form1.cs | 115 +++ IpChecker.GUI/IpChecker.csproj | 11 + IpChecker.GUI/Program.cs | 20 + IpChecker.GUI/Resources/Icon.ico | Bin 0 -> 161862 bytes IpChecker.GUI/SimpleJSON.cs | 1317 ++++++++++++++++++++++++++ 12 files changed, 3227 insertions(+) create mode 100644 IpChecker.Console/Compile.bat create mode 100644 IpChecker.Console/IpChecker.csproj create mode 100644 IpChecker.Console/Program.cs create mode 100644 IpChecker.Console/Resources/Icon.ico create mode 100644 IpChecker.Console/SimpleJSON.cs create mode 100644 IpChecker.GUI/Compile.bat create mode 100644 IpChecker.GUI/Form1.Designer.cs create mode 100644 IpChecker.GUI/Form1.cs create mode 100644 IpChecker.GUI/IpChecker.csproj create mode 100644 IpChecker.GUI/Program.cs create mode 100644 IpChecker.GUI/Resources/Icon.ico create mode 100644 IpChecker.GUI/SimpleJSON.cs diff --git a/IpChecker.Console/Compile.bat b/IpChecker.Console/Compile.bat new file mode 100644 index 0000000..5588921 --- /dev/null +++ b/IpChecker.Console/Compile.bat @@ -0,0 +1,5 @@ +@echo off +title Compile +cls +C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /win32icon:Resources\Icon.ico /t:exe /out:IpChecker.Console.exe *.cs +pause \ No newline at end of file diff --git a/IpChecker.Console/IpChecker.csproj b/IpChecker.Console/IpChecker.csproj new file mode 100644 index 0000000..fd76e04 --- /dev/null +++ b/IpChecker.Console/IpChecker.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/IpChecker.Console/Program.cs b/IpChecker.Console/Program.cs new file mode 100644 index 0000000..d30491e --- /dev/null +++ b/IpChecker.Console/Program.cs @@ -0,0 +1,92 @@ +using System; +using System.Net; + +using SimpleJSON; + +namespace IpChecker +{ + public static class Program + { + private static void Main(string[] args) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + + string ipAddress = string.Empty; + bool queryAnyKey = false; + + try + { + // If an IP address is provided as a command line argument + ipAddress = args[0]; + } + catch + { + queryAnyKey = true; + + Console.Write("\n[?] Enter the ip address\n>>> "); + ipAddress = Console.ReadLine(); + } + + dynamic ip = ParseLink(@"http://ip-api.com/json/" + ipAddress + "?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query"); + + if (ip["status"] == "fail") + Console.WriteLine("\n[x] Invalid ip address"); + + else if (ip["status"] == "noInternet") + Console.WriteLine("\n[x] No internet connection"); + + else + { + Console.WriteLine + ( + "\nIp: " + ip["query"] + + "\nContinent: " + ip["continent"] + " " + ip["continentCode"] + + "\nCountry: " + ip["country"] + " " + ip["countryCode"] + + "\nCity: " + ip["city"] + + "\nCurrency: " + ip["currency"] + + "\nRegion: " + ip["regionName"] + + "\nTime zone: " + ip["timezone"] + + "\nOffset: " + ip["offset"] + + "\nProvider: " + ip["isp"] + + "\nAs: " + ip["as"] + + "\nAs name: " + ip["asname"] + + "\nReverse: " + ip["reverse"] + + "\nOrganization: " + ip["org"] + + "\nDistrict: " + ip["district"] + + "\nZip: " + ip["zip"] + + "\nLatitude: " + ip["lat"] + + "\nLongitude: " + ip["lon"] + + "\nMobile: " + ip["mobile"] + + "\nProxy: " + ip["proxy"] + + "\nHosting: " + ip["hosting"] + + "\nGoogle maps: https://www.google.com/maps/search/?api=1&query=" + ip["lat"] + "," + ip["lon"] + ); + } + + if (queryAnyKey == true) + { + Console.Write("\n[+] Press any key to continue..."); + Console.ReadKey(); + Console.WriteLine(""); + } + } + + private static dynamic ParseLink(string link) + { + try + { + using (WebClient ipClient = new WebClient()) + { + string response = ipClient.DownloadString(link); + dynamic result = JSON.Parse(response); + + return result; + } + } + catch + { + return JSON.Parse("{\"status\":\"noInternet\"}"); + } + } + } +} \ No newline at end of file diff --git a/IpChecker.Console/Resources/Icon.ico b/IpChecker.Console/Resources/Icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ca431bd8c5fed80c9f4c22daa62bdedc185422af GIT binary patch literal 161862 zcmeHwd9W45e*f|L*1S}FmE@P?m;B*PRbIWNQYn-AC6%g|Dos)^G4JI)Q4j$^K~XkA zKv5qeTtxvDMPXPx47XKw;Pn$Ywx3G4LX&5@^pF?w zgi(6a<%IyTf#aB}1}N$#&?<8Gh)^L7Lolh@RBJWw`=}k#i|34Ip6DO%WhZMMa4HUEUNhe(0dPD zWs~e9(|uxjPchg6OZM!)qSF7Sa^hGL(}LE4CfR3Q=L=Q`AbXDSo7!q_Fes>Z1FPLP z$v!u-*EknMU(jUp^Jeq%-WN2ezR#$|wKMK0$CKoJ?e|Z9s&0H_Jo^Ku6OYUkKfgLiW^w2<2Z%8K$cP z$lEmL3n>4nWFMjZ*LqZ%j{L2*-}J5@K>kt5o^8L&%VV_MqVg%j&^Dl{?FSq4L@E1c zJ9mvr=I(Mr*?^|DpC8#jK61BPZc*KbvH_5PPq?V+z9q|vy4`0{_8R}5LB|1*ePuDp zzul<)vdw$jEqAv*xb@%`kiFLF5|jZ?3Ryt-}(I&a`@Lf zI<=>38w@x;>}ll=6e}l?fYUyEm65Et~5xZXwxI2YknYcvbtPkXvgti`jgogVS^MdLJDxg0{qfR;2TQ+^|J&zF+3c0MiWYvKP4*2}&*6Lde811Z zI6sx#Jl6+6?geA}+1@xtH`}-lQ%+IH+^qxpe%Y34NqfTjDEr^^`b^&6{UiB5JwB1m zUYuO)ve&wi&Aj2P;SHb3%GF~X?!=Bc^6a6N^2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(f&|%FdW{>oD^=$ zoC#jImiw)_p184or9W2wK>DlsgzwN_ql~oL5A*BG!h^VI-Ow^pSm|`yzi=16z4N;} O%nn_uOQ&NV=KcTXE^(g# literal 0 HcmV?d00001 diff --git a/IpChecker.Console/SimpleJSON.cs b/IpChecker.Console/SimpleJSON.cs new file mode 100644 index 0000000..437d576 --- /dev/null +++ b/IpChecker.Console/SimpleJSON.cs @@ -0,0 +1,1317 @@ +using System; +using System.Linq; +using System.Text; +using System.Collections; +using System.Globalization; +using System.Collections.Generic; + +namespace SimpleJSON +{ + public enum JSONNodeType + { + Array = 1, + Object = 2, + String = 3, + Number = 4, + NullValue = 5, + Boolean = 6, + None = 7, + Custom = 0xFF, + } + public enum JSONTextMode + { + Compact, + Indent + } + + public abstract partial class JSONNode + { + #region Enumerators + public struct Enumerator + { + private enum Type { None, Array, Object } + private Type type; + private Dictionary.Enumerator m_Object; + private List.Enumerator m_Array; + public bool IsValid { get { return type != Type.None; } } + public Enumerator(List.Enumerator aArrayEnum) + { + type = Type.Array; + m_Object = default(Dictionary.Enumerator); + m_Array = aArrayEnum; + } + public Enumerator(Dictionary.Enumerator aDictEnum) + { + type = Type.Object; + m_Object = aDictEnum; + m_Array = default(List.Enumerator); + } + public KeyValuePair Current + { + get + { + if (type == Type.Array) + return new KeyValuePair(string.Empty, m_Array.Current); + else if (type == Type.Object) + return m_Object.Current; + return new KeyValuePair(string.Empty, null); + } + } + public bool MoveNext() + { + if (type == Type.Array) + return m_Array.MoveNext(); + else if (type == Type.Object) + return m_Object.MoveNext(); + return false; + } + } + public struct ValueEnumerator + { + private Enumerator m_Enumerator; + public ValueEnumerator(List.Enumerator aArrayEnum) : this(new Enumerator(aArrayEnum)) { } + public ValueEnumerator(Dictionary.Enumerator aDictEnum) : this(new Enumerator(aDictEnum)) { } + public ValueEnumerator(Enumerator aEnumerator) { m_Enumerator = aEnumerator; } + public JSONNode Current { get { return m_Enumerator.Current.Value; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + public ValueEnumerator GetEnumerator() { return this; } + } + public struct KeyEnumerator + { + private Enumerator m_Enumerator; + public KeyEnumerator(List.Enumerator aArrayEnum) : this(new Enumerator(aArrayEnum)) { } + public KeyEnumerator(Dictionary.Enumerator aDictEnum) : this(new Enumerator(aDictEnum)) { } + public KeyEnumerator(Enumerator aEnumerator) { m_Enumerator = aEnumerator; } + public string Current { get { return m_Enumerator.Current.Key; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + public KeyEnumerator GetEnumerator() { return this; } + } + + public class LinqEnumerator : IEnumerator>, IEnumerable> + { + private JSONNode m_Node; + private Enumerator m_Enumerator; + internal LinqEnumerator(JSONNode aNode) + { + m_Node = aNode; + if (m_Node != null) + m_Enumerator = m_Node.GetEnumerator(); + } + public KeyValuePair Current { get { return m_Enumerator.Current; } } + object IEnumerator.Current { get { return m_Enumerator.Current; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + + public void Dispose() + { + m_Node = null; + m_Enumerator = new Enumerator(); + } + + public IEnumerator> GetEnumerator() + { + return new LinqEnumerator(m_Node); + } + + public void Reset() + { + if (m_Node != null) + m_Enumerator = m_Node.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return new LinqEnumerator(m_Node); + } + } + + #endregion Enumerators + + #region common interface + + public static bool forceASCII = false; // Use Unicode by default + public static bool longAsString = false; // lazy creator creates a JSONString instead of JSONNumber + public static bool allowLineComments = true; // allow "//"-style comments at the end of a line + + public abstract JSONNodeType Tag { get; } + + public virtual JSONNode this[int aIndex] { get { return null; } set { } } + + public virtual JSONNode this[string aKey] { get { return null; } set { } } + + public virtual string Value { get { return ""; } set { } } + + public virtual int Count { get { return 0; } } + + public virtual bool IsNumber { get { return false; } } + public virtual bool IsString { get { return false; } } + public virtual bool IsBoolean { get { return false; } } + public virtual bool IsNull { get { return false; } } + public virtual bool IsArray { get { return false; } } + public virtual bool IsObject { get { return false; } } + + public virtual bool Inline { get { return false; } set { } } + + public virtual void Add(string aKey, JSONNode aItem) + { + } + public virtual void Add(JSONNode aItem) + { + Add("", aItem); + } + + public virtual JSONNode Remove(string aKey) + { + return null; + } + + public virtual JSONNode Remove(int aIndex) + { + return null; + } + + public virtual JSONNode Remove(JSONNode aNode) + { + return aNode; + } + + public virtual JSONNode Clone() + { + return null; + } + + public virtual IEnumerable Children + { + get + { + yield break; + } + } + + public IEnumerable DeepChildren + { + get + { + foreach (var C in Children) + foreach (var D in C.DeepChildren) + yield return D; + } + } + + public virtual bool HasKey(string aKey) + { + return false; + } + + public virtual JSONNode GetValueOrDefault(string aKey, JSONNode aDefault) + { + return aDefault; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + WriteToStringBuilder(sb, 0, 0, JSONTextMode.Compact); + return sb.ToString(); + } + + public virtual string ToString(int aIndent) + { + StringBuilder sb = new StringBuilder(); + WriteToStringBuilder(sb, 0, aIndent, JSONTextMode.Indent); + return sb.ToString(); + } + internal abstract void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode); + + public abstract Enumerator GetEnumerator(); + public IEnumerable> Linq { get { return new LinqEnumerator(this); } } + public KeyEnumerator Keys { get { return new KeyEnumerator(GetEnumerator()); } } + public ValueEnumerator Values { get { return new ValueEnumerator(GetEnumerator()); } } + + #endregion common interface + + #region typecasting properties + + + public virtual double AsDouble + { + get + { + double v = 0.0; + if (double.TryParse(Value, NumberStyles.Float, CultureInfo.InvariantCulture, out v)) + return v; + return 0.0; + } + set + { + Value = value.ToString(CultureInfo.InvariantCulture); + } + } + + public virtual int AsInt + { + get { return (int)AsDouble; } + set { AsDouble = value; } + } + + public virtual float AsFloat + { + get { return (float)AsDouble; } + set { AsDouble = value; } + } + + public virtual bool AsBool + { + get + { + bool v = false; + if (bool.TryParse(Value, out v)) + return v; + return !string.IsNullOrEmpty(Value); + } + set + { + Value = (value) ? "true" : "false"; + } + } + + public virtual long AsLong + { + get + { + long val = 0; + if (long.TryParse(Value, out val)) + return val; + return 0L; + } + set + { + Value = value.ToString(); + } + } + + public virtual JSONArray AsArray + { + get + { + return this as JSONArray; + } + } + + public virtual JSONObject AsObject + { + get + { + return this as JSONObject; + } + } + + + #endregion typecasting properties + + #region operators + + public static implicit operator JSONNode(string s) + { + return new JSONString(s); + } + public static implicit operator string(JSONNode d) + { + return (d == null) ? null : d.Value; + } + + public static implicit operator JSONNode(double n) + { + return new JSONNumber(n); + } + public static implicit operator double(JSONNode d) + { + return (d == null) ? 0 : d.AsDouble; + } + + public static implicit operator JSONNode(float n) + { + return new JSONNumber(n); + } + public static implicit operator float(JSONNode d) + { + return (d == null) ? 0 : d.AsFloat; + } + + public static implicit operator JSONNode(int n) + { + return new JSONNumber(n); + } + public static implicit operator int(JSONNode d) + { + return (d == null) ? 0 : d.AsInt; + } + + public static implicit operator JSONNode(long n) + { + if (longAsString) + return new JSONString(n.ToString()); + return new JSONNumber(n); + } + public static implicit operator long(JSONNode d) + { + return (d == null) ? 0L : d.AsLong; + } + + public static implicit operator JSONNode(bool b) + { + return new JSONBool(b); + } + public static implicit operator bool(JSONNode d) + { + return (d == null) ? false : d.AsBool; + } + + public static implicit operator JSONNode(KeyValuePair aKeyValue) + { + return aKeyValue.Value; + } + + public static bool operator ==(JSONNode a, object b) + { + if (ReferenceEquals(a, b)) + return true; + bool aIsNull = a is JSONNull || ReferenceEquals(a, null) || a is JSONLazyCreator; + bool bIsNull = b is JSONNull || ReferenceEquals(b, null) || b is JSONLazyCreator; + if (aIsNull && bIsNull) + return true; + return !aIsNull && a.Equals(b); + } + + public static bool operator !=(JSONNode a, object b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #endregion operators + + [ThreadStatic] + private static StringBuilder m_EscapeBuilder; + internal static StringBuilder EscapeBuilder + { + get + { + if (m_EscapeBuilder == null) + m_EscapeBuilder = new StringBuilder(); + return m_EscapeBuilder; + } + } + internal static string Escape(string aText) + { + var sb = EscapeBuilder; + sb.Length = 0; + if (sb.Capacity < aText.Length + aText.Length / 10) + sb.Capacity = aText.Length + aText.Length / 10; + foreach (char c in aText) + { + switch (c) + { + case '\\': + sb.Append("\\\\"); + break; + case '\"': + sb.Append("\\\""); + break; + case '\n': + sb.Append("\\n"); + break; + case '\r': + sb.Append("\\r"); + break; + case '\t': + sb.Append("\\t"); + break; + case '\b': + sb.Append("\\b"); + break; + case '\f': + sb.Append("\\f"); + break; + default: + if (c < ' ' || (forceASCII && c > 127)) + { + ushort val = c; + sb.Append("\\u").Append(val.ToString("X4")); + } + else + sb.Append(c); + break; + } + } + string result = sb.ToString(); + sb.Length = 0; + return result; + } + + private static JSONNode ParseElement(string token, bool quoted) + { + if (quoted) + return token; + string tmp = token.ToLower(); + if (tmp == "false" || tmp == "true") + return tmp == "true"; + if (tmp == "null") + return JSONNull.CreateOrGet(); + double val; + if (double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out val)) + return val; + else + return token; + } + + public static JSONNode Parse(string aJSON) + { + Stack stack = new Stack(); + JSONNode ctx = null; + int i = 0; + StringBuilder Token = new StringBuilder(); + string TokenName = ""; + bool QuoteMode = false; + bool TokenIsQuoted = false; + while (i < aJSON.Length) + { + switch (aJSON[i]) + { + case '{': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + stack.Push(new JSONObject()); + if (ctx != null) + { + ctx.Add(TokenName, stack.Peek()); + } + TokenName = ""; + Token.Length = 0; + ctx = stack.Peek(); + break; + + case '[': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + + stack.Push(new JSONArray()); + if (ctx != null) + { + ctx.Add(TokenName, stack.Peek()); + } + TokenName = ""; + Token.Length = 0; + ctx = stack.Peek(); + break; + + case '}': + case ']': + if (QuoteMode) + { + + Token.Append(aJSON[i]); + break; + } + if (stack.Count == 0) + throw new Exception("JSON Parse: Too many closing brackets"); + + stack.Pop(); + if (Token.Length > 0 || TokenIsQuoted) + ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted)); + TokenIsQuoted = false; + TokenName = ""; + Token.Length = 0; + if (stack.Count > 0) + ctx = stack.Peek(); + break; + + case ':': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + TokenName = Token.ToString(); + Token.Length = 0; + TokenIsQuoted = false; + break; + + case '"': + QuoteMode ^= true; + TokenIsQuoted |= QuoteMode; + break; + + case ',': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + if (Token.Length > 0 || TokenIsQuoted) + ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted)); + TokenIsQuoted = false; + TokenName = ""; + Token.Length = 0; + TokenIsQuoted = false; + break; + + case '\r': + case '\n': + break; + + case ' ': + case '\t': + if (QuoteMode) + Token.Append(aJSON[i]); + break; + + case '\\': + ++i; + if (QuoteMode) + { + char C = aJSON[i]; + switch (C) + { + case 't': + Token.Append('\t'); + break; + case 'r': + Token.Append('\r'); + break; + case 'n': + Token.Append('\n'); + break; + case 'b': + Token.Append('\b'); + break; + case 'f': + Token.Append('\f'); + break; + case 'u': + { + string s = aJSON.Substring(i + 1, 4); + Token.Append((char)int.Parse( + s, + System.Globalization.NumberStyles.AllowHexSpecifier)); + i += 4; + break; + } + default: + Token.Append(C); + break; + } + } + break; + case '/': + if (allowLineComments && !QuoteMode && i + 1 < aJSON.Length && aJSON[i + 1] == '/') + { + while (++i < aJSON.Length && aJSON[i] != '\n' && aJSON[i] != '\r') ; + break; + } + Token.Append(aJSON[i]); + break; + case '\uFEFF': // remove / ignore BOM (Byte Order Mark) + break; + + default: + Token.Append(aJSON[i]); + break; + } + ++i; + } + if (QuoteMode) + { + throw new Exception("JSON Parse: Quotation marks seems to be messed up."); + } + if (ctx == null) + return ParseElement(Token.ToString(), TokenIsQuoted); + return ctx; + } + + } + // End of JSONNode + + public partial class JSONArray : JSONNode + { + private List m_List = new List(); + private bool inline = false; + public override bool Inline + { + get { return inline; } + set { inline = value; } + } + + public override JSONNodeType Tag { get { return JSONNodeType.Array; } } + public override bool IsArray { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(m_List.GetEnumerator()); } + + public override JSONNode this[int aIndex] + { + get + { + if (aIndex < 0 || aIndex >= m_List.Count) + return new JSONLazyCreator(this); + return m_List[aIndex]; + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (aIndex < 0 || aIndex >= m_List.Count) + m_List.Add(value); + else + m_List[aIndex] = value; + } + } + + public override JSONNode this[string aKey] + { + get { return new JSONLazyCreator(this); } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + m_List.Add(value); + } + } + + public override int Count + { + get { return m_List.Count; } + } + + public override void Add(string aKey, JSONNode aItem) + { + if (aItem == null) + aItem = JSONNull.CreateOrGet(); + m_List.Add(aItem); + } + + public override JSONNode Remove(int aIndex) + { + if (aIndex < 0 || aIndex >= m_List.Count) + return null; + JSONNode tmp = m_List[aIndex]; + m_List.RemoveAt(aIndex); + return tmp; + } + + public override JSONNode Remove(JSONNode aNode) + { + m_List.Remove(aNode); + return aNode; + } + + public override JSONNode Clone() + { + var node = new JSONArray(); + node.m_List.Capacity = m_List.Capacity; + foreach(var n in m_List) + { + if (n != null) + node.Add(n.Clone()); + else + node.Add(null); + } + return node; + } + + public override IEnumerable Children + { + get + { + foreach (JSONNode N in m_List) + yield return N; + } + } + + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('['); + int count = m_List.Count; + if (inline) + aMode = JSONTextMode.Compact; + for (int i = 0; i < count; i++) + { + if (i > 0) + aSB.Append(','); + if (aMode == JSONTextMode.Indent) + aSB.AppendLine(); + + if (aMode == JSONTextMode.Indent) + aSB.Append(' ', aIndent + aIndentInc); + m_List[i].WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode); + } + if (aMode == JSONTextMode.Indent) + aSB.AppendLine().Append(' ', aIndent); + aSB.Append(']'); + } + } + // End of JSONArray + + public partial class JSONObject : JSONNode + { + private Dictionary m_Dict = new Dictionary(); + + private bool inline = false; + public override bool Inline + { + get { return inline; } + set { inline = value; } + } + + public override JSONNodeType Tag { get { return JSONNodeType.Object; } } + public override bool IsObject { get { return true; } } + + public override Enumerator GetEnumerator() { return new Enumerator(m_Dict.GetEnumerator()); } + + + public override JSONNode this[string aKey] + { + get + { + if (m_Dict.ContainsKey(aKey)) + return m_Dict[aKey]; + else + return new JSONLazyCreator(this, aKey); + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (m_Dict.ContainsKey(aKey)) + m_Dict[aKey] = value; + else + m_Dict.Add(aKey, value); + } + } + + public override JSONNode this[int aIndex] + { + get + { + if (aIndex < 0 || aIndex >= m_Dict.Count) + return null; + return m_Dict.ElementAt(aIndex).Value; + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (aIndex < 0 || aIndex >= m_Dict.Count) + return; + string key = m_Dict.ElementAt(aIndex).Key; + m_Dict[key] = value; + } + } + + public override int Count + { + get { return m_Dict.Count; } + } + + public override void Add(string aKey, JSONNode aItem) + { + if (aItem == null) + aItem = JSONNull.CreateOrGet(); + + if (aKey != null) + { + if (m_Dict.ContainsKey(aKey)) + m_Dict[aKey] = aItem; + else + m_Dict.Add(aKey, aItem); + } + else + m_Dict.Add(Guid.NewGuid().ToString(), aItem); + } + + public override JSONNode Remove(string aKey) + { + if (!m_Dict.ContainsKey(aKey)) + return null; + JSONNode tmp = m_Dict[aKey]; + m_Dict.Remove(aKey); + return tmp; + } + + public override JSONNode Remove(int aIndex) + { + if (aIndex < 0 || aIndex >= m_Dict.Count) + return null; + var item = m_Dict.ElementAt(aIndex); + m_Dict.Remove(item.Key); + return item.Value; + } + + public override JSONNode Remove(JSONNode aNode) + { + try + { + var item = m_Dict.Where(k => k.Value == aNode).First(); + m_Dict.Remove(item.Key); + return aNode; + } + catch + { + return null; + } + } + + public override JSONNode Clone() + { + var node = new JSONObject(); + foreach (var n in m_Dict) + { + node.Add(n.Key, n.Value.Clone()); + } + return node; + } + + public override bool HasKey(string aKey) + { + return m_Dict.ContainsKey(aKey); + } + + public override JSONNode GetValueOrDefault(string aKey, JSONNode aDefault) + { + JSONNode res; + if (m_Dict.TryGetValue(aKey, out res)) + return res; + return aDefault; + } + + public override IEnumerable Children + { + get + { + foreach (KeyValuePair N in m_Dict) + yield return N.Value; + } + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('{'); + bool first = true; + if (inline) + aMode = JSONTextMode.Compact; + foreach (var k in m_Dict) + { + if (!first) + aSB.Append(','); + first = false; + if (aMode == JSONTextMode.Indent) + aSB.AppendLine(); + if (aMode == JSONTextMode.Indent) + aSB.Append(' ', aIndent + aIndentInc); + aSB.Append('\"').Append(Escape(k.Key)).Append('\"'); + if (aMode == JSONTextMode.Compact) + aSB.Append(':'); + else + aSB.Append(" : "); + k.Value.WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode); + } + if (aMode == JSONTextMode.Indent) + aSB.AppendLine().Append(' ', aIndent); + aSB.Append('}'); + } + + } + // End of JSONObject + + public partial class JSONString : JSONNode + { + private string m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.String; } } + public override bool IsString { get { return true; } } + + public override Enumerator GetEnumerator() { return new Enumerator(); } + + + public override string Value + { + get { return m_Data; } + set + { + m_Data = value; + } + } + + public JSONString(string aData) + { + m_Data = aData; + } + public override JSONNode Clone() + { + return new JSONString(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('\"').Append(Escape(m_Data)).Append('\"'); + } + public override bool Equals(object obj) + { + if (base.Equals(obj)) + return true; + string s = obj as string; + if (s != null) + return m_Data == s; + JSONString s2 = obj as JSONString; + if (s2 != null) + return m_Data == s2.m_Data; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONString + + public partial class JSONNumber : JSONNode + { + private double m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.Number; } } + public override bool IsNumber { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return m_Data.ToString(CultureInfo.InvariantCulture); } + set + { + double v; + if (double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out v)) + m_Data = v; + } + } + + public override double AsDouble + { + get { return m_Data; } + set { m_Data = value; } + } + public override long AsLong + { + get { return (long)m_Data; } + set { m_Data = value; } + } + + public JSONNumber(double aData) + { + m_Data = aData; + } + + public JSONNumber(string aData) + { + Value = aData; + } + + public override JSONNode Clone() + { + return new JSONNumber(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append(Value); + } + private static bool IsNumeric(object value) + { + return value is int || value is uint + || value is float || value is double + || value is decimal + || value is long || value is ulong + || value is short || value is ushort + || value is sbyte || value is byte; + } + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (base.Equals(obj)) + return true; + JSONNumber s2 = obj as JSONNumber; + if (s2 != null) + return m_Data == s2.m_Data; + if (IsNumeric(obj)) + return Convert.ToDouble(obj) == m_Data; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONNumber + + public partial class JSONBool : JSONNode + { + private bool m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.Boolean; } } + public override bool IsBoolean { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return m_Data.ToString(); } + set + { + bool v; + if (bool.TryParse(value, out v)) + m_Data = v; + } + } + public override bool AsBool + { + get { return m_Data; } + set { m_Data = value; } + } + + public JSONBool(bool aData) + { + m_Data = aData; + } + + public JSONBool(string aData) + { + Value = aData; + } + + public override JSONNode Clone() + { + return new JSONBool(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append((m_Data) ? "true" : "false"); + } + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (obj is bool) + return m_Data == (bool)obj; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONBool + + public partial class JSONNull : JSONNode + { + static JSONNull m_StaticInstance = new JSONNull(); + public static bool reuseSameInstance = true; + public static JSONNull CreateOrGet() + { + if (reuseSameInstance) + return m_StaticInstance; + return new JSONNull(); + } + private JSONNull() { } + + public override JSONNodeType Tag { get { return JSONNodeType.NullValue; } } + public override bool IsNull { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return "null"; } + set { } + } + public override bool AsBool + { + get { return false; } + set { } + } + + public override JSONNode Clone() + { + return CreateOrGet(); + } + + public override bool Equals(object obj) + { + if (object.ReferenceEquals(this, obj)) + return true; + return (obj is JSONNull); + } + public override int GetHashCode() + { + return 0; + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append("null"); + } + } + // End of JSONNull + + internal partial class JSONLazyCreator : JSONNode + { + private JSONNode m_Node = null; + private string m_Key = null; + public override JSONNodeType Tag { get { return JSONNodeType.None; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public JSONLazyCreator(JSONNode aNode) + { + m_Node = aNode; + m_Key = null; + } + + public JSONLazyCreator(JSONNode aNode, string aKey) + { + m_Node = aNode; + m_Key = aKey; + } + + private T Set(T aVal) where T : JSONNode + { + if (m_Key == null) + m_Node.Add(aVal); + else + m_Node.Add(m_Key, aVal); + m_Node = null; // Be GC friendly. + return aVal; + } + + public override JSONNode this[int aIndex] + { + get { return new JSONLazyCreator(this); } + set { Set(new JSONArray()).Add(value); } + } + + public override JSONNode this[string aKey] + { + get { return new JSONLazyCreator(this, aKey); } + set { Set(new JSONObject()).Add(aKey, value); } + } + + public override void Add(JSONNode aItem) + { + Set(new JSONArray()).Add(aItem); + } + + public override void Add(string aKey, JSONNode aItem) + { + Set(new JSONObject()).Add(aKey, aItem); + } + + public static bool operator ==(JSONLazyCreator a, object b) + { + if (b == null) + return true; + return System.Object.ReferenceEquals(a, b); + } + + public static bool operator !=(JSONLazyCreator a, object b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + if (obj == null) + return true; + return System.Object.ReferenceEquals(this, obj); + } + + public override int GetHashCode() + { + return 0; + } + + public override int AsInt + { + get { Set(new JSONNumber(0)); return 0; } + set { Set(new JSONNumber(value)); } + } + + public override float AsFloat + { + get { Set(new JSONNumber(0.0f)); return 0.0f; } + set { Set(new JSONNumber(value)); } + } + + public override double AsDouble + { + get { Set(new JSONNumber(0.0)); return 0.0; } + set { Set(new JSONNumber(value)); } + } + + public override long AsLong + { + get + { + if (longAsString) + Set(new JSONString("0")); + else + Set(new JSONNumber(0.0)); + return 0L; + } + set + { + if (longAsString) + Set(new JSONString(value.ToString())); + else + Set(new JSONNumber(value)); + } + } + + public override bool AsBool + { + get { Set(new JSONBool(false)); return false; } + set { Set(new JSONBool(value)); } + } + + public override JSONArray AsArray + { + get { return Set(new JSONArray()); } + } + + public override JSONObject AsObject + { + get { return Set(new JSONObject()); } + } + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append("null"); + } + } + // End of JSONLazyCreator + + public static class JSON + { + public static JSONNode Parse(string aJSON) + { + return JSONNode.Parse(aJSON); + } + } +} diff --git a/IpChecker.GUI/Compile.bat b/IpChecker.GUI/Compile.bat new file mode 100644 index 0000000..6cd107e --- /dev/null +++ b/IpChecker.GUI/Compile.bat @@ -0,0 +1,5 @@ +@echo off +title Compile +cls +C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe /win32icon:Resources\Icon.ico /out:IpChecker.GUI.exe *.cs +pause \ No newline at end of file diff --git a/IpChecker.GUI/Form1.Designer.cs b/IpChecker.GUI/Form1.Designer.cs new file mode 100644 index 0000000..ff71680 --- /dev/null +++ b/IpChecker.GUI/Form1.Designer.cs @@ -0,0 +1,335 @@ +using System; +using System.Drawing; +using System.Windows.Forms; +using System.ComponentModel; + +namespace IpChecker +{ + partial class Form1 + { + // Global app fore color + public Color AppForeColor = Color.Lime; + + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.titleLabel = new Label(); + this.ipLabel = new Label(); + this.ipTextBox = new TextBox(); + this.checkIpButton = new Button(); + this.googleMapsButton = new Button(); + this.randomIpButton = new Button(); + this.continentLabel = new Label(); + this.continentValue = new Label(); + this.countryLabel = new Label(); + this.countryValue = new Label(); + this.regionLabel = new Label(); + this.regionValue = new Label(); + this.cityLabel = new Label(); + this.cityValue = new Label(); + this.currencyLabel = new Label(); + this.currencyValue = new Label(); + this.timeZoneLabel = new Label(); + this.timeZoneValue = new Label(); + this.providerLabel = new Label(); + this.providerValue = new Label(); + this.mobileLabel = new Label(); + this.mobileValue = new Label(); + this.proxyLabel = new Label(); + this.proxyValue = new Label(); + this.hostingLabel = new Label(); + this.hostingValue = new Label(); + this.SuspendLayout(); + // + // checkIpButton + // + this.checkIpButton.FlatStyle = FlatStyle.Flat; + this.checkIpButton.BackColor = Color.Black; + this.checkIpButton.ForeColor = AppForeColor; + this.checkIpButton.Location = new Point(20, 370); + this.checkIpButton.Size = new Size(150, 36); + this.checkIpButton.Text = "Check IP"; + this.checkIpButton.Click += new EventHandler(this.checkIpButton_Click); + this.checkIpButton.Paint += new PaintEventHandler(this.EnabledPaint); + // + // googleMapsButton + // + this.googleMapsButton.Enabled = false; + this.googleMapsButton.FlatStyle = FlatStyle.Flat; + this.googleMapsButton.BackColor = Color.Black; + this.googleMapsButton.ForeColor = AppForeColor; + this.googleMapsButton.Location = new Point(190, 370); + this.googleMapsButton.Size = new Size(150, 36); + this.googleMapsButton.Text = "Open google maps"; + this.googleMapsButton.Click += new EventHandler(this.googleMapsButton_Click); + this.googleMapsButton.Paint += new PaintEventHandler(this.EnabledPaint); + // + // continentLabel + // + this.continentLabel.ForeColor = AppForeColor; + this.continentLabel.AutoSize = true; + this.continentLabel.Location = new Point(20, 110); + this.continentLabel.Text = "Continent: "; + // + // continentValue + // + this.continentValue.ForeColor = AppForeColor; + this.continentValue.AutoSize = true; + this.continentValue.Location = new Point(145, 110); + this.continentValue.Text = "--"; + // + // countryLabel + // + this.countryLabel.ForeColor = AppForeColor; + this.countryLabel.AutoSize = true; + this.countryLabel.Location = new Point(20, 135); + this.countryLabel.Text = "Country: "; + // + // countryValue + // + this.countryValue.ForeColor = AppForeColor; + this.countryLabel.AutoSize = true; + this.countryValue.Location = new Point(145, 135); + this.countryValue.Text = "--"; + // + // regionLabel + // + this.regionLabel.ForeColor = AppForeColor; + this.regionLabel.AutoSize = true; + this.regionLabel.Location = new Point(20, 160); + this.regionLabel.Text = "Region: "; + // + // regionValue + // + this.regionValue.ForeColor = AppForeColor; + this.regionValue.AutoSize = true; + this.regionValue.Location = new Point(145, 160); + this.regionValue.Text = "--"; + // + // cityLabel + // + this.cityLabel.ForeColor = AppForeColor; + this.cityLabel.AutoSize = true; + this.cityLabel.Location = new Point(20, 185); + this.cityLabel.Text = "City:"; + // + // cityValue + // + this.cityValue.ForeColor = AppForeColor; + this.cityValue.AutoSize = true; + this.cityValue.Location = new Point(145, 185); + this.cityValue.Text = "--"; + // + // currencyLabel + // + this.currencyLabel.ForeColor = AppForeColor; + this.currencyLabel.AutoSize = true; + this.currencyLabel.Location = new Point(20, 210); + this.currencyLabel.Text = "Currency:"; + // + // currencyValue + // + this.currencyValue.ForeColor = AppForeColor; + this.currencyValue.AutoSize = true; + this.currencyValue.Location = new Point(145, 210); + this.currencyValue.Text = "--"; + // + // timeZoneLabel + // + this.timeZoneLabel.ForeColor = AppForeColor; + this.timeZoneLabel.AutoSize = true; + this.timeZoneLabel.Location = new Point(20, 235); + this.timeZoneLabel.Text = "Time zone: "; + // + // timeZoneValue + // + this.timeZoneValue.ForeColor = AppForeColor; + this.timeZoneValue.AutoSize = true; + this.timeZoneValue.Location = new Point(145, 235); + this.timeZoneValue.Text = "--"; + // + // providerLabel + // + this.providerLabel.ForeColor = AppForeColor; + this.providerLabel.AutoSize = true; + this.providerLabel.Location = new Point(20, 260); + this.providerLabel.Text = "Internet Provider: "; + // + // providerValue + // + this.providerValue.ForeColor = AppForeColor; + this.providerValue.AutoSize = true; + this.providerValue.Location = new Point(145, 260); + this.providerValue.Text = "--"; + // + // mobileLabel + // + this.mobileLabel.ForeColor = AppForeColor; + this.mobileLabel.AutoSize = true; + this.mobileLabel.Location = new Point(20, 285); + this.mobileLabel.Text = "Mobile: "; + // + // mobileValue + // + this.mobileValue.ForeColor = AppForeColor; + this.mobileValue.AutoSize = true; + this.mobileValue.Location = new Point(145, 285); + this.mobileValue.Text = "--"; + // + // proxyLabel + // + this.proxyLabel.ForeColor = AppForeColor; + this.proxyLabel.AutoSize = true; + this.proxyLabel.Location = new Point(20, 310); + this.proxyLabel.Text = "Proxy: "; + // + // proxyValue + // + this.proxyValue.ForeColor = AppForeColor; + this.proxyValue.AutoSize = true; + this.proxyValue.Location = new Point(145, 310); + this.proxyValue.Text = "--"; + // + // hostingLabel + // + this.hostingLabel.ForeColor = AppForeColor; + this.hostingLabel.AutoSize = true; + this.hostingLabel.Location = new Point(20, 335); + this.hostingLabel.Text = "Hosting: "; + // + // hostingValue + // + this.hostingValue.ForeColor = AppForeColor; + this.hostingValue.AutoSize = true; + this.hostingValue.Location = new Point(145, 335); + this.hostingValue.Text = "--"; + // + // ipLabel + // + this.ipLabel.ForeColor = AppForeColor; + this.ipLabel.AutoSize = true; + this.ipLabel.Location = new Point(20, 70); + this.ipLabel.Text = "IP Adress:"; + // + // ipTextBox + // + this.ipTextBox.BorderStyle = BorderStyle.FixedSingle; + this.ipTextBox.BackColor = Color.Black; + this.ipTextBox.ForeColor = AppForeColor; + this.ipTextBox.Location = new Point(148, 67); + this.ipTextBox.Size = new Size(165, 20); + this.ipTextBox.TabIndex = 8; + // + // randomIpButton + // + this.randomIpButton.FlatStyle = FlatStyle.Flat; + this.randomIpButton.BackColor = Color.Black; + this.randomIpButton.ForeColor = AppForeColor; + this.randomIpButton.Location = new Point(313, 67); + this.randomIpButton.Size = new Size(20, 20); + this.randomIpButton.Text = "R"; + this.randomIpButton.Click += new EventHandler(this.randomIpButton_Click); + this.randomIpButton.Paint += new PaintEventHandler(this.EnabledPaint); + // + // titleLabel + // + this.titleLabel.AutoSize = false; + this.titleLabel.ForeColor = AppForeColor; + this.titleLabel.TextAlign = ContentAlignment.MiddleCenter; + this.titleLabel.Font = new Font("Segoe ui", 16F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(204))); + this.titleLabel.Location = new Point(120, 15); + this.titleLabel.Size = new Size(125, 26); + this.titleLabel.TabIndex = 9; + this.titleLabel.Text = "IP Checker"; + // + // Form1 + // + this.Text = "IP Checker"; + this.ClientSize = new Size(360, 420); + this.FormBorderStyle = FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.BackColor = Color.Black; + this.Controls.Add(this.titleLabel); + this.Controls.Add(this.ipLabel); + this.Controls.Add(this.ipTextBox); + this.Controls.Add(this.checkIpButton); + this.Controls.Add(this.googleMapsButton); + this.Controls.Add(this.randomIpButton); + this.Controls.Add(this.continentLabel); + this.Controls.Add(this.continentValue); + this.Controls.Add(this.countryLabel); + this.Controls.Add(this.countryValue); + this.Controls.Add(this.regionLabel); + this.Controls.Add(this.regionValue); + this.Controls.Add(this.cityLabel); + this.Controls.Add(this.cityValue); + this.Controls.Add(this.currencyLabel); + this.Controls.Add(this.currencyValue); + this.Controls.Add(this.timeZoneLabel); + this.Controls.Add(this.timeZoneValue); + this.Controls.Add(this.providerLabel); + this.Controls.Add(this.providerValue); + this.Controls.Add(this.mobileLabel); + this.Controls.Add(this.mobileValue); + this.Controls.Add(this.proxyLabel); + this.Controls.Add(this.proxyValue); + this.Controls.Add(this.hostingLabel); + this.Controls.Add(this.hostingValue); + + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + + private Label titleLabel; + private Label ipLabel; + private TextBox ipTextBox; + private Button checkIpButton; + private Button googleMapsButton; + private Button randomIpButton; + private Label continentLabel; + private Label continentValue; + private Label countryLabel; + private Label countryValue; + private Label regionLabel; + private Label regionValue; + private Label cityLabel; + private Label cityValue; + private Label currencyLabel; + private Label currencyValue; + private Label timeZoneLabel; + private Label timeZoneValue; + private Label providerLabel; + private Label providerValue; + private Label mobileLabel; + private Label mobileValue; + private Label proxyLabel; + private Label proxyValue; + private Label hostingLabel; + private Label hostingValue; + } +} \ No newline at end of file diff --git a/IpChecker.GUI/Form1.cs b/IpChecker.GUI/Form1.cs new file mode 100644 index 0000000..831bdd5 --- /dev/null +++ b/IpChecker.GUI/Form1.cs @@ -0,0 +1,115 @@ +using System; +using System.Net; +using System.Drawing; +using System.Diagnostics; +using System.Windows.Forms; +using System.Threading.Tasks; + +using SimpleJSON; + +namespace IpChecker +{ + public partial class Form1 : Form + { + private Random r = new Random(); + private dynamic ipData = null; + + public Form1() + { + InitializeComponent(); + } + + private void EnabledPaint(object sender, PaintEventArgs e) + { + Button button = (Button)sender; + string text = button.Text; + + if (button.Enabled) + button.ForeColor = AppForeColor; + + else + { + button.ForeColor = Color.FromArgb(100, 100, 100); + TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak; + TextRenderer.DrawText(e.Graphics, text, button.Font, e.ClipRectangle, Color.FromArgb(100, 100, 100), flags); + } + } + + // Generate random ip address + private void randomIpButton_Click(object sender, EventArgs e) + { + ipTextBox.Text = r.Next(1, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255); + } + + // Show location in google maps + private async void googleMapsButton_Click(object sender, EventArgs e) + { + if (ipData != null && !string.IsNullOrEmpty(ipData["lat"]) && !string.IsNullOrEmpty(ipData["lon"])) + { + string url = "https://www.google.com/maps/search/?api=1&query=" + ipData["lat"] + "," + ipData["lon"]; + await Task.Run(() => Process.Start(url)); + } + } + + private async void checkIpButton_Click(object sender, EventArgs e) + { + string ipAddress = Convert.ToString(ipTextBox.Text).Trim(); + + googleMapsButton.Enabled = false; + checkIpButton.Enabled = false; + ipTextBox.Enabled = false; + randomIpButton.Enabled = false; + + await Task.Run(() => + { + ipData = ParseLink(@"http://ip-api.com/json/" + ipAddress + "?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query"); + + if (ipData["status"] == "fail") + MessageBox.Show("Invalid ip address!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + + else if (ipData["status"] == "noInternet") + MessageBox.Show("No internet connection!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + + else + { + ipTextBox.Text = ipData["query"]; + continentValue.Text = ipData["continent"] + " (" + ipData["continentCode"] + ")"; + countryValue.Text = ipData["country"] + " (" + ipData["countryCode"] + ")"; + regionValue.Text = ipData["regionName"]; + cityValue.Text = ipData["city"]; + currencyValue.Text = ipData["currency"]; + timeZoneValue.Text = ipData["timezone"]; + providerValue.Text = ipData["isp"]; + mobileValue.Text = ipData["mobile"]; + proxyValue.Text = ipData["proxy"]; + hostingValue.Text = ipData["hosting"]; + } + + checkIpButton.Enabled = true; + ipTextBox.Enabled = true; + randomIpButton.Enabled = true; + + if (!(string.IsNullOrEmpty(ipData["lat"]) && string.IsNullOrEmpty(ipData["lon"]))) + googleMapsButton.Enabled = true; + }); + } + + private static dynamic ParseLink(string link) + { + try + { + using (WebClient ipClient = new WebClient()) + { + string response = ipClient.DownloadString(link); + dynamic result = JSON.Parse(response); + + return result; + } + } + catch + { + return JSON.Parse("{\"status\":\"noInternet\"}"); + } + } + } +} \ No newline at end of file diff --git a/IpChecker.GUI/IpChecker.csproj b/IpChecker.GUI/IpChecker.csproj new file mode 100644 index 0000000..e56da76 --- /dev/null +++ b/IpChecker.GUI/IpChecker.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/IpChecker.GUI/Program.cs b/IpChecker.GUI/Program.cs new file mode 100644 index 0000000..04aa7be --- /dev/null +++ b/IpChecker.GUI/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Windows.Forms; + +namespace IpChecker +{ + public static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + private static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} + \ No newline at end of file diff --git a/IpChecker.GUI/Resources/Icon.ico b/IpChecker.GUI/Resources/Icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ca431bd8c5fed80c9f4c22daa62bdedc185422af GIT binary patch literal 161862 zcmeHwd9W45e*f|L*1S}FmE@P?m;B*PRbIWNQYn-AC6%g|Dos)^G4JI)Q4j$^K~XkA zKv5qeTtxvDMPXPx47XKw;Pn$Ywx3G4LX&5@^pF?w zgi(6a<%IyTf#aB}1}N$#&?<8Gh)^L7Lolh@RBJWw`=}k#i|34Ip6DO%WhZMMa4HUEUNhe(0dPD zWs~e9(|uxjPchg6OZM!)qSF7Sa^hGL(}LE4CfR3Q=L=Q`AbXDSo7!q_Fes>Z1FPLP z$v!u-*EknMU(jUp^Jeq%-WN2ezR#$|wKMK0$CKoJ?e|Z9s&0H_Jo^Ku6OYUkKfgLiW^w2<2Z%8K$cP z$lEmL3n>4nWFMjZ*LqZ%j{L2*-}J5@K>kt5o^8L&%VV_MqVg%j&^Dl{?FSq4L@E1c zJ9mvr=I(Mr*?^|DpC8#jK61BPZc*KbvH_5PPq?V+z9q|vy4`0{_8R}5LB|1*ePuDp zzul<)vdw$jEqAv*xb@%`kiFLF5|jZ?3Ryt-}(I&a`@Lf zI<=>38w@x;>}ll=6e}l?fYUyEm65Et~5xZXwxI2YknYcvbtPkXvgti`jgogVS^MdLJDxg0{qfR;2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9(-rxcC};W!IV3 zE(2kfX{YlF^Zc0hFOHEN27IB@O&|?OOMV?RLw1s9T<}~k*2%n2^!WgD-ztqCJnh!Qo;IC%NrNhrdz4r2DND$IaNXyAeFF1-r1Nu+Z*`Wy%u<}E&_{A@ z=-RJdl(f&|%FdW{>oD^=$ zoC#jImiw)_p184or9W2wK>DlsgzwN_ql~oL5A*BG!h^VI-Ow^pSm|`yzi=16z4N;} O%nn_uOQ&NV=KcTXE^(g# literal 0 HcmV?d00001 diff --git a/IpChecker.GUI/SimpleJSON.cs b/IpChecker.GUI/SimpleJSON.cs new file mode 100644 index 0000000..437d576 --- /dev/null +++ b/IpChecker.GUI/SimpleJSON.cs @@ -0,0 +1,1317 @@ +using System; +using System.Linq; +using System.Text; +using System.Collections; +using System.Globalization; +using System.Collections.Generic; + +namespace SimpleJSON +{ + public enum JSONNodeType + { + Array = 1, + Object = 2, + String = 3, + Number = 4, + NullValue = 5, + Boolean = 6, + None = 7, + Custom = 0xFF, + } + public enum JSONTextMode + { + Compact, + Indent + } + + public abstract partial class JSONNode + { + #region Enumerators + public struct Enumerator + { + private enum Type { None, Array, Object } + private Type type; + private Dictionary.Enumerator m_Object; + private List.Enumerator m_Array; + public bool IsValid { get { return type != Type.None; } } + public Enumerator(List.Enumerator aArrayEnum) + { + type = Type.Array; + m_Object = default(Dictionary.Enumerator); + m_Array = aArrayEnum; + } + public Enumerator(Dictionary.Enumerator aDictEnum) + { + type = Type.Object; + m_Object = aDictEnum; + m_Array = default(List.Enumerator); + } + public KeyValuePair Current + { + get + { + if (type == Type.Array) + return new KeyValuePair(string.Empty, m_Array.Current); + else if (type == Type.Object) + return m_Object.Current; + return new KeyValuePair(string.Empty, null); + } + } + public bool MoveNext() + { + if (type == Type.Array) + return m_Array.MoveNext(); + else if (type == Type.Object) + return m_Object.MoveNext(); + return false; + } + } + public struct ValueEnumerator + { + private Enumerator m_Enumerator; + public ValueEnumerator(List.Enumerator aArrayEnum) : this(new Enumerator(aArrayEnum)) { } + public ValueEnumerator(Dictionary.Enumerator aDictEnum) : this(new Enumerator(aDictEnum)) { } + public ValueEnumerator(Enumerator aEnumerator) { m_Enumerator = aEnumerator; } + public JSONNode Current { get { return m_Enumerator.Current.Value; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + public ValueEnumerator GetEnumerator() { return this; } + } + public struct KeyEnumerator + { + private Enumerator m_Enumerator; + public KeyEnumerator(List.Enumerator aArrayEnum) : this(new Enumerator(aArrayEnum)) { } + public KeyEnumerator(Dictionary.Enumerator aDictEnum) : this(new Enumerator(aDictEnum)) { } + public KeyEnumerator(Enumerator aEnumerator) { m_Enumerator = aEnumerator; } + public string Current { get { return m_Enumerator.Current.Key; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + public KeyEnumerator GetEnumerator() { return this; } + } + + public class LinqEnumerator : IEnumerator>, IEnumerable> + { + private JSONNode m_Node; + private Enumerator m_Enumerator; + internal LinqEnumerator(JSONNode aNode) + { + m_Node = aNode; + if (m_Node != null) + m_Enumerator = m_Node.GetEnumerator(); + } + public KeyValuePair Current { get { return m_Enumerator.Current; } } + object IEnumerator.Current { get { return m_Enumerator.Current; } } + public bool MoveNext() { return m_Enumerator.MoveNext(); } + + public void Dispose() + { + m_Node = null; + m_Enumerator = new Enumerator(); + } + + public IEnumerator> GetEnumerator() + { + return new LinqEnumerator(m_Node); + } + + public void Reset() + { + if (m_Node != null) + m_Enumerator = m_Node.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return new LinqEnumerator(m_Node); + } + } + + #endregion Enumerators + + #region common interface + + public static bool forceASCII = false; // Use Unicode by default + public static bool longAsString = false; // lazy creator creates a JSONString instead of JSONNumber + public static bool allowLineComments = true; // allow "//"-style comments at the end of a line + + public abstract JSONNodeType Tag { get; } + + public virtual JSONNode this[int aIndex] { get { return null; } set { } } + + public virtual JSONNode this[string aKey] { get { return null; } set { } } + + public virtual string Value { get { return ""; } set { } } + + public virtual int Count { get { return 0; } } + + public virtual bool IsNumber { get { return false; } } + public virtual bool IsString { get { return false; } } + public virtual bool IsBoolean { get { return false; } } + public virtual bool IsNull { get { return false; } } + public virtual bool IsArray { get { return false; } } + public virtual bool IsObject { get { return false; } } + + public virtual bool Inline { get { return false; } set { } } + + public virtual void Add(string aKey, JSONNode aItem) + { + } + public virtual void Add(JSONNode aItem) + { + Add("", aItem); + } + + public virtual JSONNode Remove(string aKey) + { + return null; + } + + public virtual JSONNode Remove(int aIndex) + { + return null; + } + + public virtual JSONNode Remove(JSONNode aNode) + { + return aNode; + } + + public virtual JSONNode Clone() + { + return null; + } + + public virtual IEnumerable Children + { + get + { + yield break; + } + } + + public IEnumerable DeepChildren + { + get + { + foreach (var C in Children) + foreach (var D in C.DeepChildren) + yield return D; + } + } + + public virtual bool HasKey(string aKey) + { + return false; + } + + public virtual JSONNode GetValueOrDefault(string aKey, JSONNode aDefault) + { + return aDefault; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + WriteToStringBuilder(sb, 0, 0, JSONTextMode.Compact); + return sb.ToString(); + } + + public virtual string ToString(int aIndent) + { + StringBuilder sb = new StringBuilder(); + WriteToStringBuilder(sb, 0, aIndent, JSONTextMode.Indent); + return sb.ToString(); + } + internal abstract void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode); + + public abstract Enumerator GetEnumerator(); + public IEnumerable> Linq { get { return new LinqEnumerator(this); } } + public KeyEnumerator Keys { get { return new KeyEnumerator(GetEnumerator()); } } + public ValueEnumerator Values { get { return new ValueEnumerator(GetEnumerator()); } } + + #endregion common interface + + #region typecasting properties + + + public virtual double AsDouble + { + get + { + double v = 0.0; + if (double.TryParse(Value, NumberStyles.Float, CultureInfo.InvariantCulture, out v)) + return v; + return 0.0; + } + set + { + Value = value.ToString(CultureInfo.InvariantCulture); + } + } + + public virtual int AsInt + { + get { return (int)AsDouble; } + set { AsDouble = value; } + } + + public virtual float AsFloat + { + get { return (float)AsDouble; } + set { AsDouble = value; } + } + + public virtual bool AsBool + { + get + { + bool v = false; + if (bool.TryParse(Value, out v)) + return v; + return !string.IsNullOrEmpty(Value); + } + set + { + Value = (value) ? "true" : "false"; + } + } + + public virtual long AsLong + { + get + { + long val = 0; + if (long.TryParse(Value, out val)) + return val; + return 0L; + } + set + { + Value = value.ToString(); + } + } + + public virtual JSONArray AsArray + { + get + { + return this as JSONArray; + } + } + + public virtual JSONObject AsObject + { + get + { + return this as JSONObject; + } + } + + + #endregion typecasting properties + + #region operators + + public static implicit operator JSONNode(string s) + { + return new JSONString(s); + } + public static implicit operator string(JSONNode d) + { + return (d == null) ? null : d.Value; + } + + public static implicit operator JSONNode(double n) + { + return new JSONNumber(n); + } + public static implicit operator double(JSONNode d) + { + return (d == null) ? 0 : d.AsDouble; + } + + public static implicit operator JSONNode(float n) + { + return new JSONNumber(n); + } + public static implicit operator float(JSONNode d) + { + return (d == null) ? 0 : d.AsFloat; + } + + public static implicit operator JSONNode(int n) + { + return new JSONNumber(n); + } + public static implicit operator int(JSONNode d) + { + return (d == null) ? 0 : d.AsInt; + } + + public static implicit operator JSONNode(long n) + { + if (longAsString) + return new JSONString(n.ToString()); + return new JSONNumber(n); + } + public static implicit operator long(JSONNode d) + { + return (d == null) ? 0L : d.AsLong; + } + + public static implicit operator JSONNode(bool b) + { + return new JSONBool(b); + } + public static implicit operator bool(JSONNode d) + { + return (d == null) ? false : d.AsBool; + } + + public static implicit operator JSONNode(KeyValuePair aKeyValue) + { + return aKeyValue.Value; + } + + public static bool operator ==(JSONNode a, object b) + { + if (ReferenceEquals(a, b)) + return true; + bool aIsNull = a is JSONNull || ReferenceEquals(a, null) || a is JSONLazyCreator; + bool bIsNull = b is JSONNull || ReferenceEquals(b, null) || b is JSONLazyCreator; + if (aIsNull && bIsNull) + return true; + return !aIsNull && a.Equals(b); + } + + public static bool operator !=(JSONNode a, object b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #endregion operators + + [ThreadStatic] + private static StringBuilder m_EscapeBuilder; + internal static StringBuilder EscapeBuilder + { + get + { + if (m_EscapeBuilder == null) + m_EscapeBuilder = new StringBuilder(); + return m_EscapeBuilder; + } + } + internal static string Escape(string aText) + { + var sb = EscapeBuilder; + sb.Length = 0; + if (sb.Capacity < aText.Length + aText.Length / 10) + sb.Capacity = aText.Length + aText.Length / 10; + foreach (char c in aText) + { + switch (c) + { + case '\\': + sb.Append("\\\\"); + break; + case '\"': + sb.Append("\\\""); + break; + case '\n': + sb.Append("\\n"); + break; + case '\r': + sb.Append("\\r"); + break; + case '\t': + sb.Append("\\t"); + break; + case '\b': + sb.Append("\\b"); + break; + case '\f': + sb.Append("\\f"); + break; + default: + if (c < ' ' || (forceASCII && c > 127)) + { + ushort val = c; + sb.Append("\\u").Append(val.ToString("X4")); + } + else + sb.Append(c); + break; + } + } + string result = sb.ToString(); + sb.Length = 0; + return result; + } + + private static JSONNode ParseElement(string token, bool quoted) + { + if (quoted) + return token; + string tmp = token.ToLower(); + if (tmp == "false" || tmp == "true") + return tmp == "true"; + if (tmp == "null") + return JSONNull.CreateOrGet(); + double val; + if (double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out val)) + return val; + else + return token; + } + + public static JSONNode Parse(string aJSON) + { + Stack stack = new Stack(); + JSONNode ctx = null; + int i = 0; + StringBuilder Token = new StringBuilder(); + string TokenName = ""; + bool QuoteMode = false; + bool TokenIsQuoted = false; + while (i < aJSON.Length) + { + switch (aJSON[i]) + { + case '{': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + stack.Push(new JSONObject()); + if (ctx != null) + { + ctx.Add(TokenName, stack.Peek()); + } + TokenName = ""; + Token.Length = 0; + ctx = stack.Peek(); + break; + + case '[': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + + stack.Push(new JSONArray()); + if (ctx != null) + { + ctx.Add(TokenName, stack.Peek()); + } + TokenName = ""; + Token.Length = 0; + ctx = stack.Peek(); + break; + + case '}': + case ']': + if (QuoteMode) + { + + Token.Append(aJSON[i]); + break; + } + if (stack.Count == 0) + throw new Exception("JSON Parse: Too many closing brackets"); + + stack.Pop(); + if (Token.Length > 0 || TokenIsQuoted) + ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted)); + TokenIsQuoted = false; + TokenName = ""; + Token.Length = 0; + if (stack.Count > 0) + ctx = stack.Peek(); + break; + + case ':': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + TokenName = Token.ToString(); + Token.Length = 0; + TokenIsQuoted = false; + break; + + case '"': + QuoteMode ^= true; + TokenIsQuoted |= QuoteMode; + break; + + case ',': + if (QuoteMode) + { + Token.Append(aJSON[i]); + break; + } + if (Token.Length > 0 || TokenIsQuoted) + ctx.Add(TokenName, ParseElement(Token.ToString(), TokenIsQuoted)); + TokenIsQuoted = false; + TokenName = ""; + Token.Length = 0; + TokenIsQuoted = false; + break; + + case '\r': + case '\n': + break; + + case ' ': + case '\t': + if (QuoteMode) + Token.Append(aJSON[i]); + break; + + case '\\': + ++i; + if (QuoteMode) + { + char C = aJSON[i]; + switch (C) + { + case 't': + Token.Append('\t'); + break; + case 'r': + Token.Append('\r'); + break; + case 'n': + Token.Append('\n'); + break; + case 'b': + Token.Append('\b'); + break; + case 'f': + Token.Append('\f'); + break; + case 'u': + { + string s = aJSON.Substring(i + 1, 4); + Token.Append((char)int.Parse( + s, + System.Globalization.NumberStyles.AllowHexSpecifier)); + i += 4; + break; + } + default: + Token.Append(C); + break; + } + } + break; + case '/': + if (allowLineComments && !QuoteMode && i + 1 < aJSON.Length && aJSON[i + 1] == '/') + { + while (++i < aJSON.Length && aJSON[i] != '\n' && aJSON[i] != '\r') ; + break; + } + Token.Append(aJSON[i]); + break; + case '\uFEFF': // remove / ignore BOM (Byte Order Mark) + break; + + default: + Token.Append(aJSON[i]); + break; + } + ++i; + } + if (QuoteMode) + { + throw new Exception("JSON Parse: Quotation marks seems to be messed up."); + } + if (ctx == null) + return ParseElement(Token.ToString(), TokenIsQuoted); + return ctx; + } + + } + // End of JSONNode + + public partial class JSONArray : JSONNode + { + private List m_List = new List(); + private bool inline = false; + public override bool Inline + { + get { return inline; } + set { inline = value; } + } + + public override JSONNodeType Tag { get { return JSONNodeType.Array; } } + public override bool IsArray { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(m_List.GetEnumerator()); } + + public override JSONNode this[int aIndex] + { + get + { + if (aIndex < 0 || aIndex >= m_List.Count) + return new JSONLazyCreator(this); + return m_List[aIndex]; + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (aIndex < 0 || aIndex >= m_List.Count) + m_List.Add(value); + else + m_List[aIndex] = value; + } + } + + public override JSONNode this[string aKey] + { + get { return new JSONLazyCreator(this); } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + m_List.Add(value); + } + } + + public override int Count + { + get { return m_List.Count; } + } + + public override void Add(string aKey, JSONNode aItem) + { + if (aItem == null) + aItem = JSONNull.CreateOrGet(); + m_List.Add(aItem); + } + + public override JSONNode Remove(int aIndex) + { + if (aIndex < 0 || aIndex >= m_List.Count) + return null; + JSONNode tmp = m_List[aIndex]; + m_List.RemoveAt(aIndex); + return tmp; + } + + public override JSONNode Remove(JSONNode aNode) + { + m_List.Remove(aNode); + return aNode; + } + + public override JSONNode Clone() + { + var node = new JSONArray(); + node.m_List.Capacity = m_List.Capacity; + foreach(var n in m_List) + { + if (n != null) + node.Add(n.Clone()); + else + node.Add(null); + } + return node; + } + + public override IEnumerable Children + { + get + { + foreach (JSONNode N in m_List) + yield return N; + } + } + + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('['); + int count = m_List.Count; + if (inline) + aMode = JSONTextMode.Compact; + for (int i = 0; i < count; i++) + { + if (i > 0) + aSB.Append(','); + if (aMode == JSONTextMode.Indent) + aSB.AppendLine(); + + if (aMode == JSONTextMode.Indent) + aSB.Append(' ', aIndent + aIndentInc); + m_List[i].WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode); + } + if (aMode == JSONTextMode.Indent) + aSB.AppendLine().Append(' ', aIndent); + aSB.Append(']'); + } + } + // End of JSONArray + + public partial class JSONObject : JSONNode + { + private Dictionary m_Dict = new Dictionary(); + + private bool inline = false; + public override bool Inline + { + get { return inline; } + set { inline = value; } + } + + public override JSONNodeType Tag { get { return JSONNodeType.Object; } } + public override bool IsObject { get { return true; } } + + public override Enumerator GetEnumerator() { return new Enumerator(m_Dict.GetEnumerator()); } + + + public override JSONNode this[string aKey] + { + get + { + if (m_Dict.ContainsKey(aKey)) + return m_Dict[aKey]; + else + return new JSONLazyCreator(this, aKey); + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (m_Dict.ContainsKey(aKey)) + m_Dict[aKey] = value; + else + m_Dict.Add(aKey, value); + } + } + + public override JSONNode this[int aIndex] + { + get + { + if (aIndex < 0 || aIndex >= m_Dict.Count) + return null; + return m_Dict.ElementAt(aIndex).Value; + } + set + { + if (value == null) + value = JSONNull.CreateOrGet(); + if (aIndex < 0 || aIndex >= m_Dict.Count) + return; + string key = m_Dict.ElementAt(aIndex).Key; + m_Dict[key] = value; + } + } + + public override int Count + { + get { return m_Dict.Count; } + } + + public override void Add(string aKey, JSONNode aItem) + { + if (aItem == null) + aItem = JSONNull.CreateOrGet(); + + if (aKey != null) + { + if (m_Dict.ContainsKey(aKey)) + m_Dict[aKey] = aItem; + else + m_Dict.Add(aKey, aItem); + } + else + m_Dict.Add(Guid.NewGuid().ToString(), aItem); + } + + public override JSONNode Remove(string aKey) + { + if (!m_Dict.ContainsKey(aKey)) + return null; + JSONNode tmp = m_Dict[aKey]; + m_Dict.Remove(aKey); + return tmp; + } + + public override JSONNode Remove(int aIndex) + { + if (aIndex < 0 || aIndex >= m_Dict.Count) + return null; + var item = m_Dict.ElementAt(aIndex); + m_Dict.Remove(item.Key); + return item.Value; + } + + public override JSONNode Remove(JSONNode aNode) + { + try + { + var item = m_Dict.Where(k => k.Value == aNode).First(); + m_Dict.Remove(item.Key); + return aNode; + } + catch + { + return null; + } + } + + public override JSONNode Clone() + { + var node = new JSONObject(); + foreach (var n in m_Dict) + { + node.Add(n.Key, n.Value.Clone()); + } + return node; + } + + public override bool HasKey(string aKey) + { + return m_Dict.ContainsKey(aKey); + } + + public override JSONNode GetValueOrDefault(string aKey, JSONNode aDefault) + { + JSONNode res; + if (m_Dict.TryGetValue(aKey, out res)) + return res; + return aDefault; + } + + public override IEnumerable Children + { + get + { + foreach (KeyValuePair N in m_Dict) + yield return N.Value; + } + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('{'); + bool first = true; + if (inline) + aMode = JSONTextMode.Compact; + foreach (var k in m_Dict) + { + if (!first) + aSB.Append(','); + first = false; + if (aMode == JSONTextMode.Indent) + aSB.AppendLine(); + if (aMode == JSONTextMode.Indent) + aSB.Append(' ', aIndent + aIndentInc); + aSB.Append('\"').Append(Escape(k.Key)).Append('\"'); + if (aMode == JSONTextMode.Compact) + aSB.Append(':'); + else + aSB.Append(" : "); + k.Value.WriteToStringBuilder(aSB, aIndent + aIndentInc, aIndentInc, aMode); + } + if (aMode == JSONTextMode.Indent) + aSB.AppendLine().Append(' ', aIndent); + aSB.Append('}'); + } + + } + // End of JSONObject + + public partial class JSONString : JSONNode + { + private string m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.String; } } + public override bool IsString { get { return true; } } + + public override Enumerator GetEnumerator() { return new Enumerator(); } + + + public override string Value + { + get { return m_Data; } + set + { + m_Data = value; + } + } + + public JSONString(string aData) + { + m_Data = aData; + } + public override JSONNode Clone() + { + return new JSONString(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append('\"').Append(Escape(m_Data)).Append('\"'); + } + public override bool Equals(object obj) + { + if (base.Equals(obj)) + return true; + string s = obj as string; + if (s != null) + return m_Data == s; + JSONString s2 = obj as JSONString; + if (s2 != null) + return m_Data == s2.m_Data; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONString + + public partial class JSONNumber : JSONNode + { + private double m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.Number; } } + public override bool IsNumber { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return m_Data.ToString(CultureInfo.InvariantCulture); } + set + { + double v; + if (double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out v)) + m_Data = v; + } + } + + public override double AsDouble + { + get { return m_Data; } + set { m_Data = value; } + } + public override long AsLong + { + get { return (long)m_Data; } + set { m_Data = value; } + } + + public JSONNumber(double aData) + { + m_Data = aData; + } + + public JSONNumber(string aData) + { + Value = aData; + } + + public override JSONNode Clone() + { + return new JSONNumber(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append(Value); + } + private static bool IsNumeric(object value) + { + return value is int || value is uint + || value is float || value is double + || value is decimal + || value is long || value is ulong + || value is short || value is ushort + || value is sbyte || value is byte; + } + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (base.Equals(obj)) + return true; + JSONNumber s2 = obj as JSONNumber; + if (s2 != null) + return m_Data == s2.m_Data; + if (IsNumeric(obj)) + return Convert.ToDouble(obj) == m_Data; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONNumber + + public partial class JSONBool : JSONNode + { + private bool m_Data; + + public override JSONNodeType Tag { get { return JSONNodeType.Boolean; } } + public override bool IsBoolean { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return m_Data.ToString(); } + set + { + bool v; + if (bool.TryParse(value, out v)) + m_Data = v; + } + } + public override bool AsBool + { + get { return m_Data; } + set { m_Data = value; } + } + + public JSONBool(bool aData) + { + m_Data = aData; + } + + public JSONBool(string aData) + { + Value = aData; + } + + public override JSONNode Clone() + { + return new JSONBool(m_Data); + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append((m_Data) ? "true" : "false"); + } + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (obj is bool) + return m_Data == (bool)obj; + return false; + } + public override int GetHashCode() + { + return m_Data.GetHashCode(); + } + } + // End of JSONBool + + public partial class JSONNull : JSONNode + { + static JSONNull m_StaticInstance = new JSONNull(); + public static bool reuseSameInstance = true; + public static JSONNull CreateOrGet() + { + if (reuseSameInstance) + return m_StaticInstance; + return new JSONNull(); + } + private JSONNull() { } + + public override JSONNodeType Tag { get { return JSONNodeType.NullValue; } } + public override bool IsNull { get { return true; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public override string Value + { + get { return "null"; } + set { } + } + public override bool AsBool + { + get { return false; } + set { } + } + + public override JSONNode Clone() + { + return CreateOrGet(); + } + + public override bool Equals(object obj) + { + if (object.ReferenceEquals(this, obj)) + return true; + return (obj is JSONNull); + } + public override int GetHashCode() + { + return 0; + } + + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append("null"); + } + } + // End of JSONNull + + internal partial class JSONLazyCreator : JSONNode + { + private JSONNode m_Node = null; + private string m_Key = null; + public override JSONNodeType Tag { get { return JSONNodeType.None; } } + public override Enumerator GetEnumerator() { return new Enumerator(); } + + public JSONLazyCreator(JSONNode aNode) + { + m_Node = aNode; + m_Key = null; + } + + public JSONLazyCreator(JSONNode aNode, string aKey) + { + m_Node = aNode; + m_Key = aKey; + } + + private T Set(T aVal) where T : JSONNode + { + if (m_Key == null) + m_Node.Add(aVal); + else + m_Node.Add(m_Key, aVal); + m_Node = null; // Be GC friendly. + return aVal; + } + + public override JSONNode this[int aIndex] + { + get { return new JSONLazyCreator(this); } + set { Set(new JSONArray()).Add(value); } + } + + public override JSONNode this[string aKey] + { + get { return new JSONLazyCreator(this, aKey); } + set { Set(new JSONObject()).Add(aKey, value); } + } + + public override void Add(JSONNode aItem) + { + Set(new JSONArray()).Add(aItem); + } + + public override void Add(string aKey, JSONNode aItem) + { + Set(new JSONObject()).Add(aKey, aItem); + } + + public static bool operator ==(JSONLazyCreator a, object b) + { + if (b == null) + return true; + return System.Object.ReferenceEquals(a, b); + } + + public static bool operator !=(JSONLazyCreator a, object b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + if (obj == null) + return true; + return System.Object.ReferenceEquals(this, obj); + } + + public override int GetHashCode() + { + return 0; + } + + public override int AsInt + { + get { Set(new JSONNumber(0)); return 0; } + set { Set(new JSONNumber(value)); } + } + + public override float AsFloat + { + get { Set(new JSONNumber(0.0f)); return 0.0f; } + set { Set(new JSONNumber(value)); } + } + + public override double AsDouble + { + get { Set(new JSONNumber(0.0)); return 0.0; } + set { Set(new JSONNumber(value)); } + } + + public override long AsLong + { + get + { + if (longAsString) + Set(new JSONString("0")); + else + Set(new JSONNumber(0.0)); + return 0L; + } + set + { + if (longAsString) + Set(new JSONString(value.ToString())); + else + Set(new JSONNumber(value)); + } + } + + public override bool AsBool + { + get { Set(new JSONBool(false)); return false; } + set { Set(new JSONBool(value)); } + } + + public override JSONArray AsArray + { + get { return Set(new JSONArray()); } + } + + public override JSONObject AsObject + { + get { return Set(new JSONObject()); } + } + internal override void WriteToStringBuilder(StringBuilder aSB, int aIndent, int aIndentInc, JSONTextMode aMode) + { + aSB.Append("null"); + } + } + // End of JSONLazyCreator + + public static class JSON + { + public static JSONNode Parse(string aJSON) + { + return JSONNode.Parse(aJSON); + } + } +}