Follow us on Twitter!
Ideas are far more powerful than guns.
Saturday, April 19, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 29
Guests Online: 27
Members Online: 2

Registered Members: 82839
Newest Member: fezphantom
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Bash Script

chompish
Member

Your avatar

Posts: 8
Location:
Joined: 01.12.11
Rank:
Guest
Posted on 09-12-11 13:58
Not sure if this should be in here, but i couldn't see anywhere else it could go.

I'm trying to write a script that would set the IP address of the network card. It works, however i'm wondering if there is a more efficient way to code this?

What i've got so far seems like a lot of code for what it is doing.

Code bellow:
Code
#!/bin/bash
STRING="Working"
RECEVIED="1 received"
PINGFILE="./ping.txt"
echo $STRING

#Try DHCP
dhclient

#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt

#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 192.168.1.252
ifconfig eth0 up
fi
#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt

#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="192.168.1.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 192.168.0.252
ifconfig eth0 up
fi

#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt

#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="192.168.0.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 10.0.0.252
ifconfig eth0 up
fi

#ping external address and output to file
ping -c 1 www.google.com > /root/Desktop/ping.txt

#check for PING reply from file
if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="10.0.0.252" && ./Desktop/Start_Stuff.sh && exit
else echo "shit" && # Set IP address
ifconfig eth0 down
ifconfig eth0 10.0.1.252
ifconfig eth0 up
fi

ping -c 1 www.google.com > /root/Desktop/ping.txt

if [[ -n $(grep "$RECEVIED" /root/Desktop/ping.txt) ]]; then IPADDRESS="10.0.1.252" && ./Desktop//Start_Stuff.sh && exit
else echo "shite, its no working" &&

exit





Yes i know i have spelt received wrong :p

Any help would be appreciated
Author

RE: Bash Script

chompish
Member

Your avatar

Posts: 8
Location:
Joined: 01.12.11
Rank:
Guest
Posted on 14-12-11 21:38
Have a really posted a topic that no-one is going to give abuse on? Grin

Or give any input for that matter :right:
Author

RE: Bash Script

starofale
Member



Posts: 218
Location: England
Joined: 05.12.07
Rank:
Moderate
Posted on 15-12-11 00:30
Use functions and loops to reduce repeated code.


Try a new search engine
Author

RE: Bash Script

Arabian
Banned



Posts: 332
Location: inside you.
Joined: 22.09.10
Rank:
Apprentice
Posted on 15-12-11 02:43
starofale wrote:
Use functions and loops to reduce repeated code.


^perfect response.


G'bye y'all! I was an asshole, So korg banned me.
Author

RE: Bash Script

Mb0742
Member



Posts: 198
Location:
Joined: 26.11.07
Rank:
Apprentice
Posted on 15-12-11 09:19
Oh wow bash has functions. Cheers to this thread.

Oh wait I'm retarded, I've used fork bombs and shit. :angry:


Mb

Edited by Mb0742 on 15-12-11 09:20
javascript:alert("hi")
Author

RE: Bash Script

chompish
Member

Your avatar

Posts: 8
Location:
Joined: 01.12.11
Rank:
Guest
Posted on 15-12-11 13:25
thanks kindly Smile
Author

RE: Bash Script

Death_metal666
Member



Posts: 36
Location:
Joined: 26.05.11
Rank:
Wiseman
Warn Level: 50
Posted on 15-12-11 18:57
starofale wrote:
Use functions and loops to reduce repeated code.

Grin