Terminal command to return network class I'm trying to construct myself a primitive network scanner, and I understand that there are multiple network classes and it has become necessary for my program to determine exactly what class of network the workstation is currently connected to.

I have trialled a few options which i consider to be needlessly complicated, such as truncating various commands such as ifconfig, however these methods are arduous and messy.

Is there a single Terminal command which can return simple output such as 10.0.0.0, thereby identifying the network class?
Please reconsider and reformulate your question.

You are mixing private IPv4 address spaces and classful networks (which are deprecated or at least "old-fashioned" since 1993) and you don't consider classless networks.

In the old-fashioned concept of classful networks the leading bits 0 (Class A), 10 (Class B), 110 (Class C), 1110 (Class D) or 1111 (Class E) you get by issueing a proper ifconfig or ipconfig command completely determine the class.

So all IP-addresses starting with 


    0 - 127 belong to Class A
128 - 191 belong to Class B
192 - 223 belong to Class C
224 - 239 belong to Class D
240 - 255 belong to Class E




I can't add this as a comment because it's to long.