|
Not really a C# question, you would be better of in the Quick Answers[^] section
[edit] - wrong message type (curses default option)
|
|
|
|
|
thanks a lot, will try at that section.
|
|
|
|
|
Hi All....
I want many exe to access Database That why I use Multi-Connect to solve the problem,but I make my computer slow down,so how can I use many exe with only one connection...How to fix this problem..this in advanced
|
|
|
|
|
|
I started on a project that I expected this to be a small part of, and I now realize that it is a huge undertaking.
I thought it may be a fun exercise for those of you who are better than I, and it would be helpful to a lot of us to have.
The idea is a class that can be used to iterate nmap style ip range input (eg. 192.168.45,47-50.0/24 or 172.16.*.10-25) and return a list of ip addresses in the given ranges.
I started writing it as a TargetGroup class with the intention of being able to do something like...
TargetGroup group = new TargetGroup("192.168.45,47-50.0/24");
string[] ips = group.IPAddresses();
...And have an array, or list or whatever, containing all ip addresses.
This has proven to be a pretty big deal to build reliably and efficiently.
Also, after searching around a lot, I see that nothing like this exists. With such a great utility, and no availability, this would be a great contribution to the community.
I can't spend any more time on it, and don't know that I could ever get it where it needs to be. However, if noone else jumps on it, I will revisit it as a project when I can concentrate souly on this class. For now I am going to finish the original project using a static target list with much simpler target definitions.
If anyone chooses to tackle it, good luck. I'm sure I'm not the only person who would greatly appreciate it. I will not be responsible for any hair pulled out or sleep lost trying.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Seems pretty straightforward, unless I'm missing something...
public static IEnumerable<IPAddress> ParseIPAddressRange(string inputString)
{
string[] tokens = inputString.Split('.');
foreach (IPAddress addr in ParseIPAddressRange(tokens, 0, string.Empty))
yield return addr;
}
private static IEnumerable<IPAddress> ParseIPAddressRange(string[] tokens, int index, string partial)
{
if (index > 3)
yield return IPAddress.Parse(partial);
else if (index >= tokens.Length || tokens[index] == "*")
{
for (int x = 0; x < 256; x++)
foreach (IPAddress addr in ParseIPAddressRange(tokens, index + 1, partial + "." + x.ToString()))
yield return addr;
}
else
{
}
}
|
|
|
|
|
This is nice code. Good C# standard. It's a good start, but doesn't do what I was suggesting. It handles breaking the octets and *, but doesn't handle - ranges , ranges or /xx CIDR notation.
I would like to see something that handles input as well as nmap
Again, nice looking code though.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
That's the easy part.
Either use some regular expressions, or just split the strings manually:
1) Split on commas, and parse each component individually
2) Split each component by dashes, and count from one number to the other, just like I counted from 0 to 255
3) Split by slashes, and do whatever calculation is needed for CIDR notation (Too lazy to look that up right now)
Split() and int.Parse() can handle all of that.
|
|
|
|
|
Yeah. It's definitely just a lot of string manipulation, but to optimize it and make it reliable it's a much larger project than you would think until you start.
I started this project thinking that this would be a small part of it. I see now that the IPAM application will be easier to complete than this part alone. At least at my skill level.
I plan to make it a project of its own if noone beats me to it. At the moment the need is IPAM and I can get that done using a static list of simpler ip ranges. I can actually get the majority of my network with about 5 ranges as simple as xxx.xxx.xx-yy.0/24
xx.xx.xxx.0/22
and 172.16.0.0/16
That's easy.
If you don't think it'll be tough to build "well", as the nmap folks have, you should give it a shot.
Definitely doable, but it's a deceptive project.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Deceptive? Hardly...
foreach (string component in tokens[index].Split(','))
{
if (component.Contains('-'))
{
string[] range = component.Split('-');
if (range.Length != 2) throw new ArgumentException();
int startRange, endRange;
if (int.TryParse(range[0], out startRange) && int.TryParse(range[1], out endRange) && startRange <= endRange)
for (int x = startRange; x <= endRange; x++)
foreach (IPAddress addr in ParseIPAddressRange(tokens, index + 1, partial + "." + x.ToString()))
yield return addr;
else
throw new ArgumentException();
}
else if (component.Contains('/')
{
}
}
|
|
|
|
|
I hope this doesn't read the wrong way because this truly is nicer code than what I have, and I appreciate you trying to help. However, I'm not asking for help as much as I am presenting a challenge that I hope to get time for and thought someone may like to play with.
This would do what most people would need I'm sure, but what if you throw 172,10,159-162.0.0.1 at it?
I don't have a windows box at home, so I can only guess by looking at it, but I don't think it would work.
Should get
172.0.0.1
10.0.0.1
159.0.0.1
160.0.0.1
161.0.0.1
162.0.0.1
This looks like a crazy target range, but it is actually simpler than one that I use regularly to check gateway interfaces; with different numbers of course. The one that I actually use has a second and third octet that is about like this' first.
If anyone is able to get something near as reliable, flexible, and optimized as what nmap has in under... say... 400 lines of code, I would say that would be amazing.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Yep, that would work with the code I posted... Notice it splits by commas first, then checks each term for hyphens... And since it works recursively, it can parse out those terms in any part of the address. Granted, I typed it directly into the reply and haven't tested it, so there might be typos, but the design should work. All it needs is the /xx section.
|
|
|
|
|
I'm gonna have to check it out tomorrow. If that works, I'm very impressed and slightly ashamed.
Thanks
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
I finally got a chance to look at it, and I think this could be expanded to work in well under the 400 lines that I mentioned before. I like it.
As it is, as you know, it doesn't parse even the simplest x.x.x.x address, but it is cleaner and more efficient than my approach.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Yeah, I never got around to the simple case... That's just another else inside the comma split.
|
|
|
|
|
While I can grasp what are your goal is, your use of delimiters is not clearly explained. How are "/" and "*" and "," being used, exactly in your expressions.
My first reaction to this problem would be to "decompose" it into four calls to one procedure ... that take your range-building parameters as input ... that returns a List<int> for each of the four IP numbers, and then work on the combinatorial algorithm that generates the final list, from these four lists; which I would guess could be done using Linq.
best, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
I'm sorry. I didn't explain well.
The , would be to say this,that (this AND that)
The - would be to say this-that (this TO that) (1-3 = 1,2,3)
The * would be to say all (1-254)
The /xx would be CIDR notation
eg. 192.168.0.0/24 would be 192.168.0.1 with a mask of 255.255.255.0, so it would be 192.168.0.1 - 192.168.0.254
eg2 10.96.248.0/22 would be 10.96.248.1 with a mask of 255.255.252.0, so it would be 10.96.248.1 - 10.96.249.254
Personally I don't know if I would include the option to use something like ; to include multiple ranges, or build with the intention of the user having multiple instances of the class; one for each range.
If you want to see how useful it would be to handle ip ranges this way use nmap, or lookup some nmap examples. It would be a great class for network applications, or even a standalone application that would output text that could be piped to do things like ping sweeps. Windows is greatly lacking in this area.
Thanks for the interest.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
One more note, in case I didn't explain well enough. The part that really added difficulty for me was the ability to add multiple delimiters to each octet so that I could say
192.168.0.1
<no 193="">
194.168.0.1
195.168.0.1
196.168.0.1
by entering 192,194-196.168.0.1
This is valid input for nmap, but I don't know of any other application that will parse it correctly.
Nmap uses about 600 lines of C code to accomplish it. I'm curious if C# would be more or less. My bet is less.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Hi,
I am trying to calculate the duration between two dates in days. But it seems it is calculating always 1 less than the actual duration. I am not understanding is it a bug from MS or something. Following is the code to calculate it.
If you feel its correct one then can you please help me calculating the duration depending on the small date time in instead of calculating the date time on full date time.
string pendDuration = string.Empty;
if (pendActivityDetail.PostponeDate.HasValue)
{
pendDuration = pendActivityDetail.PostponeDate.Value.Subtract(pendActivity.ActivityDateTime).Days.ToString();
}
return pendDuration;
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
If I run this:
DateTime dt1 = new DateTime(2011, 11, 12);
DateTime dt2 = new DateTime(2011, 11, 13);
DateTime dt3 = new DateTime(2011, 11, 14);
DateTime dt4 = new DateTime(2011, 11, 15);
Console.WriteLine(dt4.Subtract(dt4).Days);
Console.WriteLine(dt4.Subtract(dt3).Days);
Console.WriteLine(dt4.Subtract(dt2).Days);
Console.WriteLine(dt4.Subtract(dt1).Days);
I get exactly what I expect:
0
1
2
3 So where do you think it is making a mistake? What values are you using, and what are you expecting?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: So where do you think it is I am making a mistake?
you are testing at midnight only. The surprises come in when the times are different.
|
|
|
|
|
You might be looking for the TimeSpan.TotalDays[^] property.
The Days property only gives you the day component of the time span... For example:
3 days, 23 hours, 59 minutes, 59 seconds:
... Days = 3, Hours = 23, Minutes = 59, Seconds = 59
... TotalDays = ~3.999, which you can round to 4
|
|
|
|
|
To start with your definition is not precise.
A timestamp consists of a date and a time.
So you MUST define exactly what values you expect with the following values.
2011-07-28 14:37:38 and 2011-08-28 14:37:38
2011-07-28 14:37:38 and 2011-08-28 14:37:37
2011-07-28 14:37:38 and 2011-08-28 14:37:39
Other variations might be important as well.
And if your timestamps have a daylight savings time component then you must define that as well.
|
|
|
|
|
I'm working on a project that requires my C# code to execute a Java program provided to me by my client.
I create a new ProcessStartInfo and setup the process as follows:
psi = new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.FileName = the java executable to be run;
psi.Arguments = the arguments for the code;
psi.WindowStyle = hidden;
I then execute the program using
using (Process exeProcess = Process.Start(psi))
{
exeProcess.WaitForExit();
}
when I execute the process the code crashes without any information.
Any thoughts on what I might be doing incorrect or
any thoughts on trying to get more information about why the crash occurs.
As a note, if I run this process outside my code in a command prompt then it works without failure.
Thanks
Jerry
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Please Wrap your code in "pre" Tag to give better readability to other users.
|
|
|
|
|