 This video is part of a series be sure to check out the description of this video for a full playlist in the last video We started looking at the if config command which I can turn on turn off IP addresses and do other stuff such as Setting IP address. Sorry turn on turn off network devices and also it can be used for setting IP addresses And other things as well We can type it in get basic information, but let's say we want to retrieve Just our IP address and here I'm talking about our local IP address what I'm taking talking about IPv4 If you're trying to connect from outside of your local network, you're gonna need to get your external your Your public IP address, which is a whole nother thing, but within your local Network this is your IP address here and obviously you can see it there But let's say you want to raise script that grabs just that there's a number of ways to do that I'm just gonna throw it together something real quick here. So I'm gonna type an IP Can I sorry if config and I'm gonna pipe it into our grep command and grep is used to search through the Information given to it and find matches. So I'm gonna say to find I Net space quotation mark and this space is important because you'll notice that there is a other lines that have INT or sorry INET and they also have the six we want just the lines that have the space So I go ahead and hit enter and there you go. We can see our IP addresses for our two devices here our wired ethernet connection and our loop back, but we still have other information on there So next I'm going to use ox. So I'm going to now run the same command. I'm gonna pipe this into a command called and Then I'm gonna say inside single quotes here braces I'm gonna say print dollar sign to So I'll hit enter and you can see that returns just my IP addresses. So let me explain that command a little bit So this is our regular output from IF config. We're taking all this output And we're then putting it into grep and rep will return only lines that are matching INET space, which would be this line and this line So next we need to get just the IP address Which would be the second column if we're going by white spaces in here In this case, we're going by spaces So this dollar sign to we're saying ock look at all look at the information given to it Which right now is two lines in my case print Columns column two basically so this would be column one and this is column two here and same here So when we do that we get our output of both IP addresses Now let's say you want to get for a specific device in this case my ETHO device my wired Connection what I can do then is I can change this up a bit. So I can say IF config There we go And I can pipe that again into grep but instead of grepping for the INET I can grep for ETHO which will return the line of ETHO, which is not doesn't have our IP address But what I can put after that is dash a Capital a it is case sensitive one which would say return the matching line and one line after it So the a is the number line so I can say match the ten lines after it or I can say two lines So that would show two lines after it. I'm gonna say one line after it perfect Okay, so now that we have that I want to now Remove that top line what I can use is the tail command tail by itself default shows the last ten lines of The input given to it. So if we want to change it right here, I only want the single line so I'm gonna say dash and one and That will give us just the last line returned and I can pipe this now into our ock command and say to Print dollar sign two for the second column and there we go We get just our IP address for that device now. This is just ways. I'm throwing it together right now I'm sure there's lots different ways that you can do this You could probably use setter ock alone without piping this many times but just off top of my head these are the tools that I'm going with and This may seem like a long command but again you can always make aliases or scripts that you can run on your system to type one command like my IP and That will then return your IP address. So all depending on what you're doing a lot of times you look at this go I have to type that every time it's like no you type it once you save it as a command that you want You're good to go now. Let me briefly talk here about something else. I'm gonna split my screen here this top screen here I'm actually logged into an older device. I have that has been updated and When I went to run to record this video I typed an if config and went wait a minute I have config looks different than I remember and if I type if config up here You can see that it definitely has a bit of a different formatting to it I don't know what at what point this change I just noticed that it may have happened a while ago and I just never noticed it But you'll notice that the lines are different. You'll notice that the line with the IP address actually says INET space ADDR colon and then our IP address So it's returning something completely different here So we have to go a different route to get the IP address So if you're working on a system that has this version of I have config Maybe it's an older system. You have a router or an old server that you just have an updated Let's go ahead and just have a quick look at that again. There's a few options here I can whoops do that. Let's go ahead and make this full screen clear this out. So Again, we need to grab this line here. Let's go the same route that we were going. So let's go I have config Let me grep Etho dash a for after one line and then I'm going to say tail Dash and one enter and you can see that now I get the line I have at this point instead of using I can just use my simple cut command here Well, I'm still gonna end up using Ock or cut so I can say cut dash D I'm really doing this off off the top of my head here F2 so what this is saying is okay. We've got this line It's saying find a delimiter of colon. So it's gonna find each colon and And it's going to divide that up into columns and actually I want F1. No F2 is correct So now I've got my IP address, but it's actually dividing it here So I'm still getting this little be cast here So what I can do is I can pipe that again into cut dash D Space space dash F1 that'll give me it or I can go back to using the Ock command I was using before of Ock print dollar sign One in this case and that gives me so either way now Again, there's people out there that are cringing right now because I'm piping piping piping piping which some people ask That's the beauty of shell scripting being able to link commands like that That's where it's real power comes in But then you'll have the people who complain that you're using more Processing power than need be because you're running all these different commands and they're right you're using more than need be It really doesn't matter unless you're on a very very lightweight system Which this is running great here on a arm system. In fact, if I go you name Dash are you see how outdated my system is or dash a you can see I'm running an arm processor here Very old kernel definitely need to update this the system here at some point but this this arm device with Very little RAM as you can see is running my piped commands fine But let's go ahead and try to shorten this up some so I'm gonna say I have config and I'm gonna pipe it just once Into Ock and I'm not the most versed on Ock. This is a command that I found online So here we're saying Ock We're gonna say forward slash iron ET add address a DDR and I'm gonna say forward slash print and then we're gonna say Substring and then parentheses and close our squiggly bracket or braces dollar sign to comma six and hit enter and you can see well That's returning Both are IP addresses, but you'll get the idea here. We're definitely shortening our command here And basically we're using Ock to not only trim up our line, but to search for the line So we're saying instead of using grep like we were up here We're saying Ock find this line and then go ahead and just go ahead and cut the line like that So we're definitely we're only running two commands here rather than one two three four five Commands here, although I am have an extra command there just to grab This particular device. I'm sure that can be done with Ock Ock and said are both great great devices I'm a lot more familiar with said but still they can do so much stuff And I know oh no such a small amount of how they work But I thought I'd show you just different options and showing how you can link these commands together On the fly and get the results that you want even though they can later on be Simplified into smaller commands. So I thank you for watching as always visit films by chris calm That's Chris of the cave. There should be a link in the description. And as always, I hope that you have a great day You