Created
January 17, 2023 22:47
-
-
Save Titory0/41da833de1b9757944ca0321be7650ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string[] ip(string ip) | |
{ | |
string part1=""; | |
string part2=""; | |
string part3=""; | |
string part4=""; | |
string write=""; | |
if(ip.Length >12 || ip.Length <4) | |
{ | |
return new string[]{"-1"}; | |
} | |
for(int w=1;w<4;w++) | |
{try{part1=ip.Substring(0,w);}catch{} | |
for(int x=1;x<4;x++) | |
{try{part2=ip.Substring(w,x);}catch{} | |
for(int y=1;y<4;y++) | |
{ | |
try{part3=ip.Substring(w+x,y);}catch{} | |
try{part4=ip.Substring(w+x+y,ip.Length-w-x-y);} | |
catch{} | |
if(part4!=""){ | |
if(Int32.Parse(part1) <255 && Int32.Parse(part2) <255 && Int32.Parse(part3) <255 && Int32.Parse(part4) <255) | |
{ | |
write=write + 'x'+ Int32.Parse(part1).ToString()+"."+Int32.Parse(part2).ToString()+"."+Int32.Parse(part3).ToString()+"."+Int32.Parse(part4).ToString(); | |
}} | |
} | |
} | |
} | |
return write.Split('x'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment