|
I'm 100% sure that the best method would be starting the windows settings programmatically and then send messages to the right buttons and IP controls to set it to automatically calculate the right value, then just copy the result in a memory variable, it's up to you to close the open windows again...
Of course you should implement that thinking in all Windows versions.
Easy, fast, always correct and working with only a little help of the Spy++ tool.
PS: I think today it will be a great programming day...
Have a nice weekend!
|
|
|
|
|
Just to make sure i'm understanding everything right.
You want to convert CIDR notation to dotted decimal?!
My approach is to convert the CIDR to a binary string (eg. /8 = 11111111000000000000000000000000), then split this string to the octets in an array (eg. [0]=11111111 [1]=00000000 [2]=00000000 [3]=00000000) and then converting each octet to decimal.
Sample source in C#:
public enum IP_TYPE
{
IPv4
, IPv6
}
public String convertCIDR2DottedDecimal(int nCIDR, IP_TYPE eType)
{
int nBits = (eType == IP_TYPE.IPv4) ? 32 : 128;
String sBinary = "";
for(int nIdx = nCIDR - 1; nIdx >= 0; nIdx--)
sBinary += "1";
for(int nIdx = nBits - nCIDR; nIdx >= 0; nIdx--)
sBinary += "0";
int nOctets = (eType == IP_TYPE.IPv4) ? 4 : 16;
String[] aOctets = new String[nOctets];
for(int nIdx = 0; nIdx < nOctets; nIdx++)
{
String sOctet = "";
for(int nOctetIdx = 0; nOctetIdx < 8; nOctetIdx++)
{
sOctet += sBinary[nOctetIdx];
}
sBinary = sBinary.Substring(8);
aOctets[nIdx] = "" + Convert.ToInt32(aOctets[nIdx], 2);
}
return String.Join(".", aOctets);
}
modified 10-Apr-15 17:27pm.
|
|
|
|
|
I've built one for IPv4 in C#. I was working on IPv6, but then I got stuck because .NET doesn't have UInt128, and couldn't be bothered anymore to look for alternatives .
string subnetMaskIPv4(int bits)
{
uint max = 4294967295;
uint mask = max << (32 - bits);
byte[] maskBytes = BitConverter.GetBytes(mask);
Array.Reverse(maskBytes);
return String.Join(".", maskBytes);
}
The quick red ProgramFOX jumps right over the Lazy<Dog> .
|
|
|
|
|
42
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I'd ask you to write a CP article about the solution you coded, and download the included source code from that article.
|
|
|
|
|
Ah.
Step 0) Invent a time machine.
Step 1) Go forward an hour.
Step 2) Copy the code.
Step 3) Go back an hour.
Step 4) Paste the code.
Done.
|
|
|
|
|
I only did it for IPv4 because I'm not familiar with the IPv6 format and too lazy to look it up.
if (bits > 31)
throw too many bits blah
unsigned char buffer[4];
int i = 0;
for (; bits >= 8; i++)
{
buffer[i] = 255;
bits -= 8;
}
if (bits > 0)
{
unsigned char ch = 255;
buffer[i++] = ch << (8 - bits)
}
for (; i < 4; i++)
buffer[i] = 0;
char result[16];
sprintf(result, "%c.%c.%c.%c", buffer[0], buffer[1], buffer[2], buffer[3]);
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I started with IPv4 as well and then simply hacked it into an IPv6 solution.
|
|
|
|
|
Weekend
|
|
|
|
|
I have office tomorrow.
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்
|
|
|
|
|
|
Oh noes! Not again!!
You have just been Sharapova'd.
|
|
|
|
|
Weekend indeed.
I'm planning to binge watch the new Daredevil series soon after my classes and internship today.
|
|
|
|
|
got 7 h to go till weekend
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
HobbyProggy wrote: 7 h Don't they have a half-day working on Fridays in Germany?
You have just been Sharapova'd.
|
|
|
|
|
Agent__007 wrote: Don't they have a half-day working on Fridays in Germany? That's nothing official but many People use their accumulated overtime for going early on fridays.
|
|
|
|
|
Aha, I see. Actually I worked with one of our German clients a few months back and the person I coordinated with used to leave after 4/4.5 hours or so on every Friday. Hence the curiosity.
Now leaving early on Fridays using accumulated overtime - that's everyone's birthright.
You have just been Sharapova'd.
|
|
|
|
|
No overtime, no comp time, just 9.5 hours a day plus the time on weekends when needed
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
Ouch!
You have just been Sharapova'd.
|
|
|
|
|
No, it's merely the fifth monday this week.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
|
Half the world remembers:
http://www.abc.net.au/news/2015-04-10/richie-benaud-dead/6009202[^]
An anachronism from the age of gentlemen.
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
modified 9-Apr-15 23:38pm.
|
|
|
|
|
well, cricket isn't exactely my cup of tea
Life's like a nose, you've got to get out of it whats in it!
|
|
|
|
|
|
One Galaxy to rule them all, One Galaxy to find them,
One Galaxy to bring them all and in the darkness bind them...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|