Get all IPs in the same network as my computer - network-programming

Is there any way to programatically (in c#) get all the other workstations that are in the same domain/subnetwork as my computer and display some information about them (if they are active, what kind of OS they have installed, their IP etc)?

nmap does this plus a ton more. Its open source.

This is a VB solution, but I'm pretty sure you'll be able to make the changes you need to make this work!
There's probably a better way, but this was a first cut.
Imports System.Net.NetworkInformation
Imports System.Directory Services
Class NetworkInfo
Function GetComputers() as list(Of String)
dim List as new list(of String)
Dim DomainEntry as new DirectoryEntry("WinNT://" + DomainInfo.GetDomain.Trim())
DomainEntry.Children.SchemaFilter.Add("computer")
For Each Machine as DirectoryEntry in DomainEntry.Children
List.Add(Machine.Name)
Next
return List
End Function
End Class
There are all sorts of useful tools knocking about in the System.Net.NetworkInformation namespace to let you capture things like the IP address, etc.

The simplest approach that I can think of (which is far from fool proof) is to send an ICMP echo request (defined in RFC 792) to 224.0.0.1. C# provides the Ping class to do this. Keep in mind though that you run the risk of dropped packets, there is also the question as to whether or not all the machines on the network support multicast.

Related

Permission needed for using GetTableNames

I have a Delphi/C++ builder app that uses Firedac to connect to a Sybase ASE database using the ODBC connection. When connection to the database, if I use the database's system admin (SA) user id/password, everything works fine and GetTableNames comes back with the list of tables in the database. But if I use a regular user to connect to database, GetTableNames comes back with an empty list. My question is, what permissions should I give the regular user for this to work.And as a side question, does anyone know what kind of command Firedac sends to database to get the table names?My code in Delphi looks like:
DBConnection.GetTableNames('', '', '', tableNameList, [TFDPhysObjectScope.osMy], [TFDPhysTableKind.tkTable]);
and in C++ Builder it looks like:
DBConnection->GetTableNames(L"", L"", L"", tableNameList, TFDPhysObjectScopes() << TFDPhysObjectScope::osMy, TFDPhysTableKinds() << TFDPhysTableKind::tkTable);
Thank youSam
For generic ODBC drivers it's the SQLTables function that FireDAC calls. Unfortunately, for the SAP Adaptive Server Enterprise driver I haven't found any information about the implementation of this function. It is the implementation detail, so it's not the issue.
The only note I found is this (for different products), for example:
sp_tables
This function corresponds to the ODBC function SQLTables.
So it's possible that the ODBC driver calls the sp_tables stored procedure in its SQLTables function implementation for that product, but no one explicitly said that (only that it corresponds).
What's more, for SAP Adaptive Server Enterprise, there is no such note by its sp_tables procedure. But you can give it a try. Or better yet, if you have some kind of command monitoring tool, use it to track what your driver calls from its SQLTables function implementation.
In any case, it is an implementation detail you should not care about, nor rely on.
The problem was NOT permissions, it was the 5th parameter of GetTableNames. The 5th parameter is the Scope which determines what kind of tables would be reported back. osMy means tables/objects owned by the logged-in user. But normally all tables in a database, are owned by SA/dbo. Adding osOther to the parameter will fix the problem. So the correct way of calling the function in Delphi would be:
DBConnection.GetTableNames('', '', '', tableNameList, [TFDPhysObjectScope.osMy, TFDPhysObjectScope.osOther], [TFDPhysTableKind.tkTable]);
and in C++ Builder it should look like:
DBConnection->GetTableNames(L"", L"", L"", tableNameList, TFDPhysObjectScopes() << TFDPhysObjectScope::osMy << TFDPhysObjectScope::osOther, TFDPhysTableKinds() << TFDPhysTableKind::tkTable);
Which will return the name of all tables that are not system tables.I must mention that I blame Embarcadero for poor documentation of TFDPhysObjectScope. The documentation does NOT explain what any of these values means. Way too often (as in this case) we see this:
Embarcadero Technologies does not currently have any additional
information. Please help us document this topic by using the
Discussion page!
And we are forced to guess and/or try-fail.

white listing solution against fortify erros does not remove the fortify errors

when i ran fority scanner it reported often misused authentication issue on the below line
hostName=java.net.InetAddress.getLocalHost().getHostName();
I had written a function which will validate this host name against the white list of host names as below.
private String validateHost(String hostName)
{
String[] PossibleHosts = {"host1","host2","host2","host4","host5",};
Integer myhostIndex = Arrays.asList(PossibleHosts).indexOf((hostName).toLowerCase());
if(myhostIndex>=0){
hostName = PossibleHosts[myhostIndex];
} else {
hostName = "";
}
return hostName;
}
which will be called by below line
hostName=validateHost(java.net.InetAddress.getLocalHost().getHostName());
But when i run the fority scan for the next time , it still shows issue on the same line even after i have done the validaiton. what can be done to remove the fortify error.
To answer you, let me explain how Fortify detects this issue, why it's included, then what to do about it.
How Fortify detects this issue: It's basically a super grep. It just finds anywhere you're using java.net.InetAddress.getLocalHost().getHostName() and complains. It is unaffected by data validation.
Why do this? Because this function is sometimes used for security purposes, and it should not be. For example, imagine a dev wanted to trust all messages from their own domain, they might use this to determine where a message came from. But then the security of their system relies on DNS, which is not secure. (See the Details tab for more info.)
What to do: First, make sure that what you're trying to do with java.net.InetAddress.getLocalHost().getHostName() is safe. Basically, that you're not trying to secure your system with this code. Then ignore the finding. At most companies I help, you would write a short explanation of why this code is OK, put it in the comment field of the Issue Summary tab, and mark the Analysis as "Not an Issue." At some places, you could also suppress it. If you're getting a ton of these, you can create a Filter that will knock out the whole category, but realize that you might also knock out some real issues that way.
Source of information: Consultant at Fortify Software 2008-2010, independent application security consultant since then.

How to filter wireshark to display only packets between a server and a client?

I am new to wireshark and trying to write simple filters. What i am trying to do is the following: I want to write a filter so that only the packets between my computer and a specified server appear in the packets pane. Here is what i tried:
ip.src==159.20.94.8 and ip.dst==10.1.1.7
First one is the ip address of my computer, and second one is the ip address of the server. But there is also the opposite of this, in which source is the server and destination is my computer.
ip.src==10.1.1.7 and ip.dst==159.20.94.8
So my question is, how can i combine these two filters? Or is there a simpler way for this filtering?
Thanks
Use ip.addr==159.20.94.8 and ip.addr==10.1.1.7
I know that doesn't seem to make sense, but ip.addr matches either source or destination.
Use ip.addr==10.0.0.1 or ip.addr==10.0.0.2.
Using the OR operator will give you results in both ways(Source and Destination).

Some questions about building a network-accessible, multi-user, programmable, interactive environment

Introduction
I've been attempting to build this project for many weeks now, and trying multiple solutions that I can't get my head around. Let me describe the project a little. It's a text-based server, that players can login to (via telnet or a client), essentially like a MUD. They can then create and interact with 'objects', giving them 'verbs' and 'properties'.
The server is basically just a database of 'objects', each object has an ID, a name, a location (which is another object), a list of its contents (objects) and some other flags. Objects can have 'verbs' and 'properties'. Properties are just stored data (string, int, float, w/e). Verbs are methods/functions. Objects are interacted with using commands such as "put something in container". An old version of the server already exists, it's called LambdaMOO. I'm attempting to re-create it since it hasn't been updated in a very, very long time.
You can read more in-depth about how objects, verbs and properties should work at: http://bit.ly/17XIqjY
An Example
Let me describe what I'd like. Imagine we have an object. Object #256, it's called "Button". It has the property "count" along with all the default properties that are inherited from it's parent (i.e. 'description'). It has one "verb" on it, called "push". This verb contains this code:
this.count += 1;
this.description = "This button has been pushed " + this.count + " times.";
player.tell("You press the button and feel a chill run down your spine.");
When the player types 'push button' on the server, the 'push' verb will run and output
You press the button and feel a chill run down your spine.
If you then look at the button, you'll see it's updated description.
Note that player in the above script refers the object of the player executing the verb. tell is another verb, on the player object. However the tell verb has a flag saying it is executable from other verbs.
What language?
My main question is what languages can I use for the 'verbs'? I've tried using node.js and the 'vm' library. I've tried using C# to parse C#. I've tried using C# to parse JavaScript. The issue I keep getting is that I have no way of controlling the permissions of the verbs and properties. If I translate them to literal functions in JavaScript, I can't determine which object they are running on and what permissions it should have. If a user calls a function on another users object, I have no way of intercepting that call and stopping it if the permissions aren't correct. I'm not entirely fussed as to which language is used for the verb code it just needs to be "sandboxed". Properties need to be only readable/writeable when they are set to be so by the user, same with verbs. I imagine I could use a language with overloading (like PHP's __get, __set, __call).
I need to also be able to inject these variables into the verb: (mostly determined from the command typed, unless the verb is being called from another verb)
player (object) the player who typed the command
this (object) the object on which this verb was found
caller (object) this will be the same as ‘player’, unless another
verb calls the command in which case it is the object
containing that verb.
verb (string) the first word of the command
argstr (string) everything after the first word of the command
args (list of strings) a list of the words in ‘argstr’
dobjstr (string) the direct object string found during parsing
dobj (object) the direct object value found during matching
prepstr (string) the prepositional phrase found during parsing
iobjstr (string) the indirect object string
iobj (object) the indirect object value
I also need to be able to access any object from any other object (so long as the permissions work out).
// Object #128. Verb: multiply Prep: this none this Perms: +r +x
return (args[0] * args[1]);
// Object #256. Verb: square Prep: this none this Perms: +r +x
return #128:multiply(args[0], args[0]);
// Object #512. Verb: touch Prep: any any this Perms: +r
// Has a property (int) 'size' on it.
this.size = #256:square(this.size);
this.description = "It's a large button, it spans " + this.size + " metres.";
player:tell("You touch the button, it gets bigger.");
The user could then push button and the button object's size property would be squared.
Recommended Reading
I highly recommend you to read the document at http://bit.ly/17XIqjY for a more in-depth idea of how the system should work.
It is also recommended you read the following documents, as μMOO is based upon LambdaMOO and it’s methodology:
https://en.wikipedia.org/wiki/LambdaMOO
https://en.wikipedia.org/wiki/MOO
http://www.hayseed.net/MOO/manuals/ProgrammersManual_toc.html
http://www.moo.mud.org/
I take this question as asking for a language that could do what you need. That's what I'll try to answer.
First, this task is hopelessly unsuited to any mainstream or imperative language such as C# or Java. I wouldn't even think about it. Javascript is possible, but not what it's good at and nothing specific to recommend it.
Second, if you had the right skills, it would be an excellent opportunity to design an entirely new language and spend the next year or two getting it working. People really do that, but I don't recommend it unless you like that kind of masochistic experience. [I do.]
So my recommendation is that you widen your language experience until you find a match. Of the languages I know moderately well, Ruby is the best to try first. As soon as you said inject these variables into the verb you made me think of Ruby, because lots of Ruby software (including Rails) is built exactly like that. Forget Python, Perl and Javascript: I really don't think they will hack it.
Beyond Ruby you might contemplate Lua. I haven't used it much recently, and it may not suit, but it is widely used as a games scripting language.
Beyond that are the true functional languages. There is the most ancient of them all: Lisp. You can do absolutely anything in Lisp, including implementing the language you were looking for in the first place. Then there are Scala and Haskell, to name just two. They are mind-bending to learn, but well suited to the kind of problem you have.
Not much of an answer because it basically says: learn each of these languages in turn until you find one that works for you. [Happy to help further if I can. I have fond memories of Moo.]

Indy 10 and setting socket options

Maybe the solution to this is very simple and I'm just too dumb to see it.
I need to recompile an old application with Indy 10 and there's this line that used to be
inUDPServer.Binding.SetSockOpt(Id_IPPROTO_IP, Id_IP_ADD_MEMBERSHIP, PChar(#mreq), SizeOf(mreq));
but the new TIdSocketHandle.SetSockOpt takes 3 integers.
Now how am I supposed to provide the ip_mreq? Just passing the imr_multiaddr.S_addr results in an #10014 Error - Buffer fault.
Maybe one of you guys has an idea.
Cheers Andy
Use the TIdSocketHandle.AddMulticastMembership() method instead (if your version of Indy 10 does not have that method available, then you will have to update to a newer snapshot first), eg:
inUDPServer.Binding.AddMulticastMembership('Group IP address');
It adds the TIdSocketHandle.IP address to the membership of the specified Group IP. IPs can be specified as either IPv4 or IPv6, depending on the setting of the TIdSocketHandle.IPVersion property.
Alternatively, consider using the TIdIPMCastServer and TIdIPMCastClient components instead of TIdUDPServer directly.

Resources