How to convert an Ip Address Instance[generateed by using IPAddress.Parse method] back to a IP string.
Observation:--
The ToString() method is not working..
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 7, 2012, 2:31 AM EDT
If I run this code:
then the output is:
If you're seeing something different, then it could conceivably be an OS or .NET version problem. I'm using Windows 7 and .NET 4.0.
Swapnasagar Panda19 reputationPosted Aug 7, 2012, 9:22 PM EDT
I am using .net framework 4.0 , but os is windows xp sp3. So is there any problem with it, because in the ipv6 generation code what u ve given , there i am not getting this desired o/p.my last 32 bits are coming as ipv4 format.
Swapnasagar Panda19 reputationPosted Aug 7, 2012, 9:36 PM EDT
U r absolutely right. I checked in windows 7 O.S and found that the code is working properly.But can u suggest me any way, so that it ll work in every O.S.
Thanks a lot for ur help till now. Please suggest any alternative.
VulpesRank #55 · 29.2K reputationPosted Aug 8, 2012, 12:36 AM EDT
http://www.c-sharpcorner.com/forums/thread/182052/generating-the-next-value-of-a-valid-ipv6-format-ip-add.aspx
should work under any OS because I'm not using the IPAddress class at all.
Swapnasagar Panda19 reputationPosted Aug 8, 2012, 1:41 AM EDT
But the same IP i can write like 2001:0db8:85a3::8a2e:0370:7334
And the code fail in this case, as u r spliting : only. So the first approach is the better approach as that is a more generalised way. Apart from the O.S problem. Actually i chked the diff. also. The IPAddress.Parse() methos is behaving diff. for both the OS. Please suggest if any.
Thanx
Swapnasagar
VulpesRank #55 · 29.2K reputationPosted Aug 8, 2012, 3:13 AM EDT
However, it's not difficult to change my latest code so that it now deals with abbreviated addresses - it still prints them out in expanded form but I imagine that's not a problem: