FORUMS
Remove All Ads from XDA

[SCRIPT] Change Hostname v6 08/07/2012

355 posts
Thanks Meter: 126
 
By Terror_1, Senior Member on 28th November 2011, 08:57 PM
Post Reply Email Thread
This will also be the last update to this script for the foreseeable future. Someone else is more than welcome to take what is here and run with it though.


08-07-2012 fixed a few typos and problems with quotes.

01-29-2012 added some variables to check for the existence of things and get correct paths.

01-06-2012 fixed hostname path.

01-02-2012 Updated to truly work on all devices.


Check it out and let me know what you think.

Big thanks to cdesai for pointing out a nice little enhancement.

This is version 5 of this script.
This script is designed to change the hostname of your device so that you can access it through your network by name instead of android_0123456789ABCEDF.

Your device will also be able to be seen at your router by the new name as well.

Code:
#!/system/bin/sh
#change devName to whatever you want.
devName="changeMe"
#random variables 
devHostPath=$(which hostname)
devGetPath=$(which getprop)
devSetPath=$(which setprop)

if [ "$($devGetPath net.hostname)" = "$devName" ]
then
	echo "Device hostname does not need to be changed."
else
	echo "Device hostname is being changed to $devName."
	$devHostPath $devName
	$devSetPath net.hostname $devName
	if [ "$($devGetPath net.hostname)" != "$devName" ]
	then
		echo "Device hostname has not been changed."
	else
		echo "Device hostname has been successfully changed."
	fi
fi
Download Hostname.sh
  1. Download Hostname.sh to your device.
  2. Use a text editor to change the "changeMe" in the script to whatever you want. [Keep the quotes]
  3. Use Script Manager to run the script.
  4. The script output will tell you if the command has completed successfully.

Once it has been run your device will be named whatever you change the "changeMe" to.

*Additionally, this script should be able to be run on any device without issues but I have only tested this on Galaxy Nexus AOKP and Droid Bionic Eclipse v3.0.

**Standard disclaimer, I am in no way responsible for ANYTHING that happens to your phone that you have done.

***This code is provided free of charge and is released with no warranty explicit or implied.

If you find this post useful or it helped in any way please hit the thanks button.
The Following 25 Users Say Thank You to Terror_1 For This Useful Post: [ View ] Gift Terror_1 Ad-Free
 
 
23rd December 2011, 06:37 PM |#2  
Senior Member
Flag Denver
Thanks Meter: 8
 
More
Can anyone confirm this worked for them? Doesn't seem to be working for me.
The Following User Says Thank You to NeWcS For This Useful Post: [ View ] Gift NeWcS Ad-Free
31st December 2011, 02:35 PM |#3  
Terror_1's Avatar
OP Senior Member
Thanks Meter: 126
 
More
What's the output when you run it?

And when you run it a second time?

You can check at your router as well by logging into it and checking the DHCP leases.

Oh, I figured this was assumed, but you have to have root and run it as root.
The Following User Says Thank You to Terror_1 For This Useful Post: [ View ] Gift Terror_1 Ad-Free
2nd January 2012, 05:06 AM |#4  
Member
Thanks Meter: 12
 
Donate to Me
More
Quote:
Originally Posted by Terror_1

What's the output when you run it?

And when you run it a second time?

You can check at your router as well by logging into it and checking the DHCP leases.

Oh, I figured this was assumed, but you have to have root and run it as root.

It didn't work for me either, but your effort is much appreciated!
The Following User Says Thank You to ZaInT_ For This Useful Post: [ View ] Gift ZaInT_ Ad-Free
2nd January 2012, 07:07 AM |#5  
cdesai's Avatar
Recognized Developer
Flag IN YOUR HEAD
Thanks Meter: 4,122
 
Donate to Me
More
Not all roms will have bash, and even those which have it is mostly in /system/bin

Using /system/bin/sh would be the best way!

From my fingers to your eyez
The Following User Says Thank You to cdesai For This Useful Post: [ View ]
2nd January 2012, 08:30 AM |#6  
Diablo67's Avatar
Senior Member
Flag Ħ†℃ ∃Ṽϴ 4Ḡ
Thanks Meter: 2,826
 
Donate to Me
More
Thanks,works perfect for me on the HTC EVO.
The Following User Says Thank You to Diablo67 For This Useful Post: [ View ] Gift Diablo67 Ad-Free
2nd January 2012, 02:46 PM |#7  
Terror_1's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by cdesai

Not all roms will have bash, and even those which have it is mostly in /system/bin

Using /system/bin/sh would be the best way!

From my fingers to your eyez

Good call.
I will get it fixed when I find a couple moments.

OP has been updated with the change, works fine on my bionic though untested on anything else.
The Following 2 Users Say Thank You to Terror_1 For This Useful Post: [ View ] Gift Terror_1 Ad-Free
2nd January 2012, 04:09 PM |#8  
cdesai's Avatar
Recognized Developer
Flag IN YOUR HEAD
Thanks Meter: 4,122
 
Donate to Me
More
Quote:
Originally Posted by Terror_1

Good call.
I will get it fixed when I find a couple moments.

OP has been updated with the change, works fine on my bionic though untested on anything else.

Yet another idea, you can specify the host name while executing the script as an argument (quick changes )
You can use read devname and if it's empty you can get model no. From build.prop

From my fingers to your eyez
2nd January 2012, 04:42 PM |#9  
Terror_1's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by cdesai

Yet another idea, you can specify the host name while executing the script as an argument (quick changes )
You can use read devname and if it's empty you can get model no. From build.prop

From my fingers to your eyez

I left it static so that it can be run at boot and will always have the same name. The model could work but it is more for changing the name to something you want rather than being dictated what it will be.

Oh and depending on your model you could have a space or other special in it.
3rd January 2012, 03:07 AM |#10  
Senior Member
Flag Buôn Mê Thuột
Thanks Meter: 93
 
More
Hi everybody !
in the old version I have to follow the instructions, but when starting the Script Manager notice shall not be allowed and notice was not found, I'm using xperia arc s, please tell me why? sr my english is not good
3rd January 2012, 01:27 PM |#11  
Terror_1's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Are you running this as root using the skull and crossbones icon?
Post Reply Subscribe to Thread

Tags
change hostname, device name, hostname not showing

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes